#include <bits/stdc++.h>
using namespace std;
vector<int> factors(int x) {
  vector<int> f;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      f.push_back(i);
      if (i * i != x) {
        f.push_back(x / i);
      }
    }
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  int p, y;
  cin >> p >> y;
  for (int i = int(y); i >= int(p + 1); i--) {
    auto f = factors(i);
    bool ok = true;
    for (auto &each : f) {
      if (each <= p) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
