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