#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int p, y, i, flag = 0;
  cin >> p >> y;
  if (y % 2 == 0) y--;
  for (i = y; i > p; i -= 2) {
    long long int fl = 0;
    long long int temp = sqrt(y);
    long long int lo = min(temp, p);
    for (long long int j = 3; j <= lo; j += 2) {
      if (i % j == 0) {
        fl = 1;
        break;
      }
    }
    if (fl != 1) {
      cout << i << endl;
      flag = 1;
      break;
    }
  }
  if (flag == 0) cout << -1 << endl;
}
