#include using namespace std; using ll = long long; struct Miller_Rabin { unsigned long long mul_mod(unsigned long long a, unsigned long long b, unsigned long long m) { unsigned long long ans = 0; #ifdef LOCAL if(a > b) std::swap(a, b); while(b){ if(b & 1){ ans += a; if(ans >= m) ans -= m; } if((a <<= 1) >= m) a -= m; b >>= 1; } #else ans = (unsigned long long)((__int128)(a) * (__int128)(b) % m); #endif return ans; } unsigned long long pow_mod(unsigned long long x, unsigned long long n, unsigned long long m) { if (m == 1) return 0; unsigned long long r = 1; unsigned long long y = x % m; while (n) { if (n & 1) r = mul_mod(r, y, m); y = mul_mod(y, y, m); n >>= 1; } return r; } bool is_prime(unsigned long long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; unsigned long long d = n - 1; while (d % 2 == 0) d /= 2; static std::vector> bases = {{2, 6, 61}, {2, 325, 9375, 28178, 450775, 9780504, 1795265022}}; for (long long a : bases[d > 4759123141]) { unsigned long long t = d; unsigned long long y = pow_mod(a, t, n); if(a % n){ while (t != n - 1 && y != 1 && y != n - 1) { y = mul_mod(y, y, n); t <<= 1; } } if (y != n - 1 && t % 2 == 0) return false; } return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll l, r; cin >> l >> r; constexpr int th = 10'000'000; vector p; vector tb(th + 1); for(int i = 2; i <= th; i += 2) tb[2] = true; for(int i = 3; i <= th; i += 2){ if(tb[i]) continue; p.emplace_back(i); for(int j = 3, d = 2 * i; j <= th; j += d){ tb[j] = true; } } Miller_Rabin MR; int idx = 0; ll v = p[idx] * p[idx] * p[idx] * p[idx]; while(v <= r){ ll v2 = p[idx] * p[idx]; for(int j = idx + 1; v2 * p[j] * p[j] < r; j++){ ll v3 = v2 * p[j]; ll d = (l + v3 - 1) / v3; ll cur = d * v3; while(cur <= r){ if(MR.is_prime(d)){ cout << cur << '\n'; return 0; } d++; cur += v3; } } idx++; v = p[idx] * p[idx] * p[idx] * p[idx]; } cout << "-1\n"; }