#include using namespace std; const int M = 200000; int myhash(int a) { if (a < 10) return a; int ret = 0; while (a) { ret += a % 10; a /= 10; } return myhash(ret); } int main() { vector isP(M, true); isP[0] = isP[1] = false; for (int i = 2; i <= M; i++) { if (isP[i]) { for (int j = 2*i; j <= M; j += i) { isP[j] = false; } } } int K, N; cin >> K >> N; vector ps; for (int i = K; i <= N; i++) if (isP[i]) ps.push_back(i); set st; int ri = 0; int id = -1; int M_len = -1; for (int le = 0; le < ps.size(); le++) { while (ri < ps.size() && st.count(myhash(ps[ri])) == 0) { st.insert(myhash(ps[ri])); ri++; } if (M_len <= ri - le) { M_len = ri - le; id = le; } if (ri == le) ri++; else st.erase(myhash(ps[le])); } cout << ps[id] << endl; }