#include <bits/stdc++.h>
using namespace std;
int sieve[31623 + 5];
vector<long long int> prime;
void ComputeSieve() {
  memset(sieve, 0, sizeof sieve);
  for (long long int a = 2; a <= 31623; a++) {
    if (sieve[a]) continue;
    prime.push_back(a);
    for (long long int b = a * a; b <= 31623; b += a) {
      sieve[b] = a;
    }
  }
}
long long int modexp(long long int b, long long int e, long long int m) {
  long long int r = 1;
  while (e > 0) {
    if ((e & 1) == 1) {
      r = (r * b) % m;
    }
    e >>= 1;
    b = (b * b) % m;
  }
  return (long long int)r;
}
int main() {
  ComputeSieve();
  long long int p, y, num;
  scanf("%I64d %I64d", &p, &y);
  long long int ans = -1;
  for (long long int a = y % 2 ? y : y - 1; a > p; a -= 2) {
    bool val = false;
    for (int b = 0;
         b < prime.size() && prime[b] * prime[b] <= a && prime[b] <= p; b++) {
      if (a % prime[b] == 0) {
        val = true;
        break;
      }
    }
    if (!val) {
      ans = a;
      break;
    }
  }
  printf("%I64d\n", ans);
}
