#include <bits/stdc++.h>
using namespace std;
int y, p, np[1000001];
vector<int> pr;
void seeve() {
  for (int i = 2; i <= 1000000; i++) {
    if (np[i]) continue;
    pr.push_back(i);
    for (int j = i + i; j <= 1000000; j += i) np[j] = 1;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  seeve();
  cin >> p >> y;
  for (int i = y; i > p; i--) {
    bool fnd = 0;
    for (auto u : pr) {
      if (u * u > i) break;
      if (u > p) break;
      if (i % u == 0) {
        fnd = 1;
        break;
      }
    }
    if (!fnd) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  cout.flush();
  return 0;
}
