#include using namespace std; const int MAX_N = 200010; int K,N; vector prime; bool flag[MAX_N]; int sieve(int N){ memset(flag, true, sizeof(flag)); for (int i = 2; i <= N; i++){ if (flag[i]){ if (K <= i)prime.push_back(i); for (int j = i + i; j <= N; j+= i){ flag[j] = false; } } } } int calc(int num){ while (true){ int res = 0; while (num){ res += num % 10; num /= 10; } if (res <= 9)return res; num = res; } } int main(){ cin >> K >> N; sieve(N); vector array; for (int i = 0; i < prime.size(); i++){ array.push_back(calc(prime[i])); } int head = 0; int tail = 0; set used; int ans = 0; int ansele = -1; // for (const auto &val : prime){ // printf("%02d ", val); // } // cout << endl; // for (const auto &val : array){ // printf("%02d ", val); // } // cout << endl; while (tail < array.size()){ if (used.count(array[tail]) == 0){ used.insert(array[tail++]); if (ans < (tail - head)){ ans = tail - head; ansele = prime[head]; }else if (ans == (tail - head) && ansele < prime[head]){ ans = tail - head; ansele = prime[head]; } }else{ while (true){ if (head == tail)break; if (array[head] == array[tail]){ used.erase(array[head++]); break; }else{ used.erase(array[head++]); } } } } cout << ansele << endl; }