#include <bits/stdc++.h>
using namespace std;
long long i, m, n, sum, p, y;
bool f(long long x) {
  for (int ii = 2; ii <= sqrt(x) && ii <= p; ii++)
    if (x % ii == 0) return false;
  return true;
}
int main() {
  cin >> p >> y;
  for (i = y; i > p; i--) {
    if (f(i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
