#include using namespace std; int N, K; vector prime; bool used[10]; int dp[10] = {0}; void Prime(){ int i, j, k; if(K <= 2) prime.push_back(2); for(i = 3; i <= 200000; i += 2){ k = 0; for(j = 3; j <= sqrt(i); j += 2){ if(i % j == 0){ k = 1; break; } } if(k == 0 && K <= i && i <= N) prime.push_back(i); } return; } int Hash(int num){ int res = 0; while (num > 0){ res += num % 10; num /= 10; } if (res >= 10) return Hash(res); return res; } int main(void){ cin >> K >> N; Prime(); int j = 0, p_head = 0, p_len = 0; for(int i = 0; i < prime.size(); ++i){ int i_h = Hash(prime[i]); ++dp[i_h]; while(dp[i_h] > 1){ int j_h = Hash(prime[j++]); --dp[j_h]; } if(i - j + 1 >= p_len){ p_head = prime[j]; p_len = i - j + 1; } } cout << p_head << endl; return 0; }