#include <bits/stdc++.h>
using namespace std;
bool prime(int n, int p) {
  for (int i = 2; i * i <= n && i <= p; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  int p, y, mx = 0;
  cin >> p >> y;
  for (int i = y; i >= p + 1; i--) {
    if (prime(i, p)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
