#include template T in() { abort(); return T(); } template<> std::string in() { std::string str; std::cin >> str; return str; } template<> int in() { int x; scanf("%d", &x); return x; } template void out(T x) { abort(); } template<> void out(const char* x) { printf("%s\n", x); } template<> void out(std::string x) { std::cout << x << std::endl; } template<> void out(int x) { printf("%d\n", x); } template<> void out(long x) { printf("%ld\n", x); } bool isprime[212345]; void init() { for(int i = 0; i < 212345; ++i) { isprime[i] = true; } isprime[0] = isprime[1] = false; for(int i = 2; i < 1000; ++i) { if( not isprime[i] ) continue; for(int j = i * i; j < 212345; j+=i) { isprime[j] = false; } } } int f(int x) { if( x < 10 ) return x; int t = 0; while( x != 0 ) { t += x % 10; x /= 10; } return f(t); } int main() { init(); int x = in(); int y = in(); std::vector primes; std::vector cod; for(int i = x; i <= y; ++i) { if( not isprime[i] ) continue; primes.push_back(i); cod.push_back(f(i)); } int res = 0; int max = 0; for(int i = 0; i < (int)primes.size(); ++i) { bool check[10] = {}; int j; for(j = i;;++j) { if( j >= (int)primes.size() ) break; if( check[cod[j]] ) break; check[cod[j]] = true; } if( max <= j - i ) { max = j - i; res = primes[i]; } } out(res); return 0; }