import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int k = sc.nextInt(); int n = sc.nextInt(); ArrayList prime = new ArrayList(); ArrayList F = new ArrayList(); for(int i = k; i <= n; i++) { if(isP(i)) prime.add(i); } Collections.sort(prime); for(int i = 0; i < prime.size(); i++) { F.add(f(prime.get(i))); } int right = 0; int ans = 0; int len = 0; int[] kosuu = new int[100]; for(int i = 0; i < prime.size(); i++) { int[] b = kosuu; b[f(prime.get(i))]++; while(right < prime.size() - 1) { if(b[prime.get(right + 1)] > 0) { break; } else { b[prime.get(right + 1)]++; right++; } } int t = right - i + 1; if(len <= t) { ans = prime.get(i); len = t; } } } public static boolean isP(int n) { int p = 0; for(int i = 2; (i * i) <= n; i++) { if((n % i) == 0) p++; } if(p == 0) return true; return false; } public static int f(int n) { if(n < 10) return n; int q = 0; for(int i = 0; (int)Math.pow(10, i) <= n; i++) { int t = n / (int)Math.pow(10, i); q += (t % 10); } return f(q); } }