#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--) #define PI acos(-1.0) #define DEBUG(C) cerr << C << endl; #define VI vector #define VII vector #define VL vector #define VLL vector #define VD vector #define VDD vector #define PII pair #define PDD pair #define PLL pair #define VPII vector #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort(ALL(a)) #define REVERSE(a) reverse(ALL(a)) #define MP make_pair #define EB emplace_back #define FORE(a, b) for (auto &&a : b) #define FIND(s, n) (s.find(n) != s.end()) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; int K, N; int hs[200010]; vector sieve_of_eratosthenes(int n) { vector is(n+1, true); vector res; is[0] = false; is[1] = false; for (int i = 2; i <= n; i++) { if (is[i]) { res.emplace_back(i); for (int j = i*2; j <= n; j+=i) { is[j] = false; } } } return res; } int makeHash(int num) { if (num < 10) return num; int res = 0; while (num) { res += num % 10; num /= 10; } return makeHash(res); } void out(vector v) { FORE(el, v) cout << el.first << " " << el.second << endl; } int main(void) { cin >> K >> N; REP(i, 200010) hs[i] = makeHash(i); PII ans = MP(0, 0); int maxsize = 0; set hsset; auto primes = sieve_of_eratosthenes(N + 10); vector v; FORE(el, primes) { if (el < K) continue; if (N < el) break; v.EB(MP(el, hs[el])); } int j = 0; //out(v); REP(i, v.size()) { while (true) { if (j >= v.size()) break; if (FIND(hsset, v[j].second)) { break; } else { hsset.insert(v[j++].second); } } if (maxsize <= hsset.size()) { maxsize = hsset.size(); ans = MP(v[i].first, v[j].first); } hsset.erase(v[i].second); } //cerr << ans.first << " " << ans.second << " " << maxsize << endl; cout << ans .first << endl; return 0; }