#include #include #include using namespace std; int digitsum(string x){ int nw = 0; for(int i = 0; x.size() > i; i++){ nw += x[i]-'0'; } if(nw < 10){ return nw; }else { return digitsum(to_string(nw)); } } bool isPrime(int x){ if(x == 1)return false; for(int i = 2; x >= i*i; i++){ if(!(x%i))return false; } return true; } int main(){ int k,n;cin>>k>>n; queue nw; set x; int ans = 0; int ansp = -1; for(int i = k; n >= i; i++){ if(isPrime(i)){ int t = digitsum(to_string(i)); while(x.count(t)){ int z = nw.front();nw.pop(); x.erase(digitsum(to_string(z))); } x.insert(t); nw.push(i); if(nw.size() > ans){ ans = nw.size(); ansp = nw.front(); }else if(nw.size() == ans){ ansp = nw.front(); } } } cout << ansp << endl; }