#include <bits/stdc++.h>
using namespace std;
long long p, y;
bool bisa(long long x) {
  long long akar = (long long)sqrt(x);
  for (long long i = 2; i <= akar; i++)
    if (x % i == 0 && i <= p) return false;
  return true;
}
int main() {
  cin >> p >> y;
  long long start = -1;
  while (y > p) {
    if (bisa(y)) {
      cout << y << "\n";
      return 0;
    }
    --y;
  }
  cout << -1 << "\n";
}
