#define REP(i,n) for(int i=0; i<(int)(n); i++) #include #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int main(){ const int k = getInt(); const int n = getInt(); vector p; vector h; for(int i = max(2, k); i <= n; i++){ bool ok = true; for(int j = 2; j * j <= i; j++) if(i % j == 0){ ok = false; break; } if(!ok) continue; p.push_back(i); int hh = i; while(hh >= 10){ int t = 0; while(hh){ t += hh % 10; hh /= 10; } hh = t; } h.push_back(hh); } int len = 0; int ans = 0; int fst = 0; set s; REP(i,p.size()){ if(s.count(h[i])){ do{ s.erase(h[fst]); }while(h[fst++] != h[i]); } s.insert(h[i]); // printf("%d(%d): %d\n", p[i], h[i], p[fst]); if(len <= i - fst + 1){ len = i - fst + 1; ans = p[fst]; } } printf("%d\n", ans); return 0; }