#include <bits/stdc++.h>
using namespace std;
bool fre(int a, int p) {
  int r = min(p, (int)floor(sqrt(a)));
  for (int c = 2; c <= r; c++)
    if (a % c == 0) return false;
  return true;
}
int main() {
  int p, y;
  cin >> p >> y;
  for (int i = y - (y + 1) % 2; i > p; i -= 2) {
    if (fre(i, p)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
