#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long mod1 = 1e9 + 7;
const int inf = 1.2e18;
const int maxL = 20;
const int maxn = 4e5 + 100;
const int baze = 330;
int n;
int p;
bool check(int x) {
  if (x <= p) return 0;
  for (int i = 2; i * i <= x and i <= p; i++)
    if (x % i == 0) return 0;
  return 1;
}
int32_t main() {
  cin >> p >> n;
  for (int i = n; i >= 0; i--)
    if (n - i >= 10000)
      break;
    else if (check(i))
      return cout << i << endl, 0;
  cout << -1 << endl;
}
