#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int L,R; cin >> L >> R; int Need = R; vector prime(Need+1,true); prime.at(0) = false; prime.at(1) = false; for(int i=2; i*i<=Need; i++){ if(!prime.at(i)) continue; for(int k=i*i; k<=Need; k+=i) prime.at(k) = false; } vector P; for(int i=L; i<=R; i++) if(prime.at(i)) P.push_back(i); int anslen = 0,ansp = -1; vector already(10); queue> Q; for(auto p : P){ int num = p; while(p >= 10){ int next = 0; while(p) next += p%10,p /= 10; p = next; } while(already.at(p)){ auto[ign,p2] = Q.front(); Q.pop(); already.at(p2) = false; } already.at(p) = true; Q.push({num,p}); if(Q.size() >= anslen) anslen = Q.size(),ansp = Q.front().first; } cout << ansp << endl; }