#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int inf = 1 << 30;
int n, t;
vector<int> prime;
bool d[100009];
void sieve() {
  d[0] = d[1] = true;
  for (int i = 2; i <= 100000; i++) {
    if (d[i]) continue;
    prime.push_back(i);
    for (int j = i + i; j <= 100000; j += i) d[j] = true;
  }
}
int main() {
  sieve();
  int x, y, ans;
  ans = -1;
  scanf("%d", &x);
  scanf("%d", &y);
  while (1) {
    if (y == x) break;
    bool isp = false;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] > x) break;
      if (y % prime[i] == 0) {
        isp = true;
        break;
      }
    }
    if (isp == false) {
      ans = y;
      break;
    }
    y--;
  }
  printf("%d\n", ans);
}
