#include <bits/stdc++.h>
using namespace std;
bool qry(long long int n, long long int p) {
  long long int k = 0, in;
  for (long long int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      k = 1;
      in = i;
      break;
    }
  }
  if (k == 0)
    return true;
  else {
    if (in > p) return true;
    return false;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int p, y, flag = 0;
  cin >> p >> y;
  for (long long int i = y; i > p; --i) {
    if (qry(i, p)) {
      flag = 1;
      cout << i << endl;
      break;
    }
  }
  if (flag == 0) cout << -1 << endl;
}
