#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int L,R; cin >> L >> R; vector P, isP(R + 1, 1); isP[0] = isP[1] = 0; for(int i = 1; i <= R; i++) { if(isP[i]) { if(L <= i && i <= R) P.push_back(i); for(int j = i + i; j <= R; j += i) { isP[j] = 0; } } } int N = P.size(); vector H(N); rep(i,N) { 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, 0); for(L = 0, R = 0; L < N; L++) { while(R < N && cnt[H[R]] == 0) cnt[H[R]]++, R++; if(ans <= R - L) { ans = R - L; fir = P[L]; } cnt[H[L]]--; } cout << fir << endl; }