#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int ttt = 1e9 + 1, tts = -1e9 - 1;
int da[700];
int isp(int test, int p) {
  for (int i = 2; i <= sqrt(test); i++) {
    if (test % i == 0) {
      if (i > p)
        return 1;
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  int p, y;
  cin >> p >> y;
  while (y != p) {
    if (isp(y, p)) {
      cout << y << endl;
      return 0;
    }
    y--;
  }
  cout << -1 << endl;
}
