#include #include #include #include #include #include #include #include #include #define rep(i, a) FOR(i, 0, a) #define FOR(i, a, b) for(int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair P; struct edge{ int to, time, cost; }; const int max = 200001; bool isPrime[max]; int data[max]; bool ex[10]; int main(){ rep(i, max)isPrime[i] = true; isPrime[0] = isPrime[1] = false; for (int i = 2; i * i <= max; ++i){ if (isPrime[i]){ for (int j = i * 2; j < max; j += i)isPrime[j] = false; } } int n, m; std::cin >> n >> m; int s = 0; FOR(i, n, m + 1){ if (isPrime[i]){ data[s] = i; ++s; } } int f = 0, size = 0, ans = data[0]; rep(i, s){ while (ex[data[i] % 9])ex[data[f] % 9] = false, ++f; ex[data[i] % 9] = true; if (i - f + 1 >= size)size = i - f + 1, ans = data[f]; } std::cout << ans << std::endl; return 0; }