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