#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; inline int hashfn(int x) { while (x >= 10) { string s = to_string(x); int sum = 0; for (char c : s) sum += c - '0'; x = sum; } return x; } int main() { int k, n; cin >> k >> n; vector isPrime(n + 1, true); isPrime[0] = isPrime[1] = false; for (ll i = 2; i <= n; i++) { if (isPrime[i]) { for (ll j = i * i; j <= n; j += i) { isPrime[j] = false; } } } vector> p; for (int i = k; i <= n; i++) { if (isPrime[i]) p.push_back({ i, hashfn(i) }); } pair ans = { 0, 0 }; set st; int l = 0, r = 0; while (r < p.size()) { while (r < p.size() && !st.contains(p[r].second)) { st.insert(p[r].second); r++; } if (r - l >= ans.first) ans = { r - l, p[l].first }; st.erase(p[l].second); l++; } cout << ans.second << endl; return 0; }