#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const ULL Z = 5000000; bool sieve[Z + 1]; ULL bull[Z + 1]; ULL offset; int main() { ULL L, R; cin >> L >> R; offset = max(Z, R) - Z; rep(i, Z + 1) bull[i] = i; sieve[0] = sieve[1] = true; for (ULL i = 2; i < Z; i++) { if (sieve[i]) continue; if (i <= 1000) for (ULL j = i * i; j < Z; j += i) sieve[j] = true; for (ULL j = i - (offset + i - 1) % i - 1; j <= Z; j += i) bull[j] = min(bull[j], i); } ULL ans = 0, val = 0; for (ULL i = max(offset, L) - offset; i <= R - offset; i++) if (bull[i] != i) if (val <= bull[i]) { val = bull[i]; ans = offset + i; } cout << ans << endl; return 0; }