#include <bits/stdc++.h>
using namespace std;
const int INF = 1031231234;
const int MOD = 1000000007;
vector<int> primes;
int sqrt(int num) {
  for (int i = 0; i < num; i++) {
    if (i * i >= num) return i;
  }
}
void sieve(int p, int y) {
  bool isPrime[1000000];
  int sq = sqrt(y);
  memset(isPrime, true, sizeof(isPrime));
  for (int i = 2; i <= sq; i++) {
    if (!isPrime[i]) continue;
    primes.push_back(i);
    for (int j = i * i; j <= sq; j += i) {
      isPrime[j] = false;
    }
  }
}
bool isPrime(int i, int threshold) {
  for (int p : primes) {
    if (p > threshold) return true;
    if (i % p == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int p, y;
  cin >> p >> y;
  if (p >= y) {
    cout << -1 << '\n';
    return 0;
  }
  sieve(p, y);
  for (int i = y; i > p; i--) {
    if (isPrime(i, p)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
