#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int p, y;
  cin >> p >> y;
  for (int i = y; i > p; i--) {
    bool ok = false;
    for (int j = 2; j <= p; j++) {
      if (j * j > i) break;
      if (i % j == 0) {
        ok = true;
        break;
      }
    }
    if (!ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
