#include #define int long long #define REP(i, b) for(int i = 0; i < (b); i++) #define REPS(i, b) for(int i = 1; i <= (b); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using pi = pair; using vi = vector; using vs = vector; using vb = vector; using vpi = vector; using vvi = vector; using vvb = vector; const int INF = 1e10; const int MOD = 1e9+7; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int h(int n) { int res = 0; while(n > 0) { res += n % 10; n /= 10; } if(res >= 10) return h(res); return res; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); int K, N; cin >> K >> N; vb isPrime(200001, true); isPrime[0] = isPrime[1] = false; for(int i = 2; i <= 200000; i++) { if(isPrime[i]) { for(int j = 2*i; j <= 200000; j += i) isPrime[j] = false; } } vpi table; for(int i = K; i <= N; i++) { if(isPrime[i]) table.push_back(make_pair(i, h(i))); } vb v(10, false); int r = 0, x = table[0].first; int len = 0; for(int l = 0; l < table.size(); l++) { while(r < table.size() && !v[table[r].second]) { v[table[r].second] = true; r++; } if(len <= r-l) { len = r-l; x = table[l].first; } v[table[l].second] = false; } cout << x << endl; }