#include using namespace std; #define rep(i,n) for(int i = 0;i < (n);i++) using ll = long long; using P =pair; ll INF = 1LL << 60; int ans[210000]; vector isprime(210000,1); int dfs(int p){ if(ans[p] != 0)return ans[p]; if(p < 10)return ans[p] = p; int s = p; int sum = 0; while(s > 0){ sum += (s % 10); s /= 10; } return ans[p] = dfs(sum); } int main(){ int k,n; cin >> k >> n; isprime[1] = 0; for(int i = 2;i <= n;i++){ if(isprime[i] == 0)continue; for(int j = 2*i; j <= n;j+=i){ isprime[j] = 0; } } vector

hash; for(int i = k;i <= n;i++){ if(isprime[i]){ hash.push_back(P(dfs(i),i)); } } int res = 0; int ans2 = 0; for(int i = 0;i < hash.size();i++){ set st; int cnt = i; while(cnt < hash.size()){ st.insert(hash[cnt].first); if(st.size() != (cnt - i + 1)){ cnt --;break; } cnt++; } cnt = st.size(); if(res <= cnt){ res = cnt; ans2 = hash[i].second; } } cout << ans2 << endl; }