#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9 + 7;
long long p, n;
int check(int n) {
  for (int i = 2; i <= p and i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> p >> n;
  for (int i = n; i > p; i--) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
