#include <bits/stdc++.h>
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
  if (x < y) x = y;
}
using namespace std;
bool ch(int x, int p) {
  for (int i = 2; i <= min(min((int)sqrt(x) + 8, x - 1), p); i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int main() {
  int p, y;
  cin >> p >> y;
  for (int i = y; i > p; i--) {
    if (ch(i, p)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
