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(); Prime[] used = new Prime[10]; TreeSet primes = new TreeSet(); int max = 0; int maxNumber = 0; for (int i = k; i <= n; i++) { if (!isPrime(i)) { continue; } Prime p = new Prime(i); if (used[p.hashCode()] == null) { used[p.hashCode()] = p; primes.add(p); } else { Prime x = used[p.hashCode()]; used[p.hashCode()] = null; while (primes.lower(x) != null) { Prime tmp = primes.lower(x); primes.remove(x); x = tmp; used[x.hashCode()] = null; } primes.remove(x); used[p.hashCode()] = p; primes.add(p); } if (max <= primes.size()) { max = primes.size(); maxNumber = primes.first().number; } } System.out.println(maxNumber); } static class Prime implements Comparable { int number; int hash; public Prime(int number) { this.number = number; this.hash = getHash(number); } public int hashCode() { return hash; } public boolean equals(Object o) { Prime another = (Prime) o; return number == another.number; } public int compareTo(Prime another) { return number - another.number; } private int getHash(int x) { while (x >= 10) { int y = x; x = 0; while (y > 0) { x += y % 10; y /= 10; } } return x; } } static boolean isPrime(int x) { if (x < 2) { return false; } for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } }