#include using namespace std; const int SZ = 200000; int dp[200001]; int g(int v) { if(v < 10) return (v); return (g(v / 10) + v % 10); } int f(int v) { if(~dp[v]) { return (dp[v]); } else if(v >= 10) { return (dp[v] = f(g(v))); } else { return (dp[v] = v); } } int main() { bool prime[SZ + 1] = {}; prime[1] = true; for(int i = 2; i * i <= SZ; ++i) { if(!prime[i]) { for(int j = i + i; j <= SZ; j += i) prime[j] = true; } } memset(dp, -1, sizeof(dp)); int K, N; cin >> K; cin >> N; vector< int > primes; for(int i = K; i <= N; i++) { if(!prime[i]) primes.push_back(i); } int tail = 0, ret = 0, p = 0; bool val[10] = {}; for(int i = 0; i < primes.size(); ++i) { while(tail < primes.size() && !val[f(primes[tail])]) { val[f(primes[tail])]++; ++tail; } if(ret <= tail - i) { p = primes[i]; } ret = max(ret, tail - i); val[f(primes[i])] = false; } cout << p << endl; }