#include <bits/stdc++.h>
using namespace std;
long long p, y;
bool light(long long x) {
  for (long long i = 2; i <= p && i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> p >> y;
  if (y % 2 == 0) --y;
  while (y > p) {
    if (light(y)) return cout << y << endl, 0;
    y -= 2;
  }
  cout << -1;
}
