#include using namespace std; template using min_priority_queue = priority_queue,greater>; template void outvec(vector &v){ bool b = false; for(auto i : v){ if(b) cout << " "; else b = true; cout << i; } cout << endl; } template void invec(vector &v){ for(auto &i : v){ cin >> i; } } template bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } void yn(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; } bool debug; bool randomInput; bool debugOutput; int numOfTestCase; using ans_type = int; void input(){ if(numOfTestCase > 1){ ; } if(randomInput){ } else{ } return; } void output_input(){ ; } int hsh(int x){ int rtn = 0; while(x){ rtn += x%10; x /= 10; } if(rtn < 10) return rtn; else return hsh(rtn); } ans_type calc(){ int K, N; cin >> K >> N; vector V(N+1, true); vector P; for(int i = 2; i <= N; i++){ if(V[i]){ P.push_back(i); for(int j = 2 * i; j <= N; j += i){ V[j] = false; } } } vector Q; for(int p : P){ if(K <= p && p <= N) Q.push_back(p); } int M = Q.size(); vector H(M); for(int i = 0; i < M; i++){ H[i] = hsh(Q[i]); } int l = 0; int r = 0; int s = 0; int best_l = 0; int best_r = 0; while(r < M){ if(s>>H[r]&1){ s -= 1<= best_r - best_l){ best_l = l; best_r = r; } } cout << Q[best_l] << endl; //outvec(Q); return ans_type(); } ans_type calc_simple(){ return ans_type(); } void output(ans_type ans){ return; } int main(){ debug = 0; randomInput = 0; debugOutput = 0; numOfTestCase = 1; srand(time(NULL)); cout << fixed << setprecision(12); if(numOfTestCase == 0) cin >> numOfTestCase; if(debug){ for(int i = 0; i < numOfTestCase; i++){ input(); ans_type ans = calc(); ans_type ansSimple = calc_simple(); if(ans != ansSimple){ output_input(); output(ans); output(ansSimple); } } } else{ for(int i = 0; i < numOfTestCase; i++){ input(); output(calc()); } } return 0; }