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