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[10]; kosuu[F.get(0)]++; while(right < prime.size() - 1) { if(kosuu[F.get(right + 1)] > 0) { break; } else { kosuu[F.get(right + 1)]++; right++; } } int c = right + 1; if(len <= c) { ans = prime.get(0); len = c; } for(int i = 1; i < prime.size(); i++) { kosuu[F.get(i - 1)]--; while(right < prime.size() - 1) { if(kosuu[F.get(right + 1)] > 0) { break; } else { kosuu[F.get(right + 1)]++; right++; } } int t = right - i + 1; if(len <= t) { ans = prime.get(i); len = t; } } System.out.println(ans); } public static boolean isP(int n) { int p = 0; for(int i = 2; (i * i) <= n; i++) { if((n % i) == 0) p++; } if(n == 1) return false; 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; i < 10; i++) { int t = n / (int)Math.pow(10, i); q += (t % 10); } return f(q); } }