#include using namespace std; int n, m; int cnt[10]; bool isprime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++){ if (x % i == 0) return false; } return true; } int hash_(int x) { stringstream ss; ss << x; string s; ss >> s; if (s.size() == 1) return s[0] - '0'; int sum = 0; for (char c : s) sum += c - '0'; return hash_(sum); } int main() { cin >> n >> m; vector ps; vector hs; for (int i = n; i <= m; i++){ if (isprime(i)){ ps.push_back(i); hs.push_back(hash_(i)); } } int l = 0, r = 0; int len = 0, res = 0; while (r < ps.size()){ cnt[hs[r]]++; while (cnt[hs[r]] == 2){ cnt[hs[l++]]--; } if (len <= r - l + 1){ res = ps[l]; len = r - l + 1; } r++; } cout << res << endl; }