#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int p, y;
bool correct(long long int x) {
  for (long long int i = 2; i * i <= x; ++i) {
    if (x % i == 0 && i <= p) return 0;
  }
  return 1;
}
signed main() {
  cin >> p >> y;
  while (y > p && !correct(y)) --y;
  if (y > p)
    cout << y << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
