#include <bits/stdc++.h>
using namespace std;
const int MX = 1 << 17;
const int MOD = 1000000007;
const long long mod2 = 1000000007 * 1LL * 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long p, n;
  cin >> p >> n;
  long long ans = -1;
  for (long long i = n; i > p; i--) {
    long long j = 2;
    int fl = 1;
    while (j <= p && j * j <= i) {
      if (i % j == 0) {
        fl = 0;
        break;
      }
      j++;
    }
    if (fl) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
