#include <bits/stdc++.h>
using namespace std;
long p, y;
bool is(long x) {
  if (!(x & 1)) return 0;
  long sx = sqrt(x);
  for (long i = 3; i <= min(p, sx); i += 2)
    if (x % i == 0) return 0;
  return 1;
}
int main() {
  long i;
  cin >> p >> y;
  for (i = y; i >= p + 1; i--) {
    if (is(i)) break;
  }
  cout << ((i == p) ? -1 : i);
}
