import java.util.*;
import java.io.*;
public class Main
{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int M = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
boolean[] c = calc();
int min = 0, sum = 0;
for(int i = M; i <= N; i++){
if(!c[i]){
if(min == 0)
min = i;
sum += i;
}
}
if(min == 0)
System.out.println("-1");
else
System.out.println(sum + "\n" + min);
}
public static boolean[] calc(){
boolean[] check = new boolean[10001];
check[1] = true;
for(int i = 2; i < 10001; i++){
if(check[i])
continue;
for(int j = i*2; j < 10001; j+=i)
check[j] = true;
}
return check;
}
}