#include using namespace std; int main(){ cin.tie(nullptr)->sync_with_stdio(false); int L, R; cin >> L >> R; vector P, is_P(R + 1, 1); is_P[0] = is_P[1] = 0; for(long long i = 2; i <= R; ++i){ if(is_P[i]){ if(L <= i && i <= R) P.emplace_back(i); for(long long j = i * i; j <= R; j += i){ is_P[j] = 0; } } } const int N = P.size(); vector H(N); for(int i = 0; i < N; ++i){ int x = P[i]; while(!(x < 10)){ string s = to_string(x); x = 0; for(char c: s) x += c - '0'; } H[i] = x; } int ans = 0, fir = -1; vector cnt(10); for(int L = 0, R = 0; L < N; ++L){ while(R < N && cnt[H[R]] == 0) ++cnt[H[R++]]; if(ans <= R - L){ ans = R - L; fir = P[L]; } cnt[H[L]]--; } cout << fir << endl; return 0; }