#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long p, y;
  cin >> p >> y;
  while (y > p) {
    long long k = 1e9;
    for (long long i = 2; i <= (long long)sqrt(y); i++) {
      if (y % i == 0) {
        k = min(k, i);
      }
    }
    if (k > p) {
      cout << y;
      return 0;
    }
    y--;
  }
  cout << -1;
  return 0;
}
