#include #include "bits/stdc++.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; const int INF = 1e8; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) using namespace std; typedef pair P; bool prime[200001]; vector prime_numbe; bool check[10]; void check_inite() { for (int i = 0; i < 10; i++) { check[i] = false; } } void shieve(int x, int y) { for (int i = 2; i <= y; i++) { if (!prime[i]) { if (i >= x) { prime_numbe.push_back(i); } for (int j = i * 2; j <= y; j += i) { prime[j] = true; } } } } int has(int x) { int s = 0; while (x / 10 != 0) { s = x % 10; x /= 10; x += s; } return x; } int main() { int k, n; cin >> k >> n; shieve(k, n); /* for (int i = 0; i < prime_numbe.size(); i++) { cout << prime_numbe[i] << endl; }*/ int left = 0, right = 0; int ct = 0; int ans = 0; int tmp = 0; for (left = 0; left < prime_numbe.size(); left++) { for (right = left; right < prime_numbe.size(); right++) { int hashnum = has(prime_numbe[right]); if (!check[hashnum]) { ct++; check[hashnum] = true; /*cout << hashnum << " " << prime_numbe[right] << endl;*/ } else { break; } } if (tmp <= ct) { ans = max(ans, prime_numbe[left]); /* cout << ans << endl;*/ tmp = ct; } ct = 0; check_inite(); } cout << ans << endl; return 0; }