#include <bits/stdc++.h>
using namespace std;
long long p, r, ans, flag = 0;
bool zhi(long long num) {
  long long nn = sqrt(num);
  int temp = min(nn, p);
  for (int i = 2; i <= temp; i++) {
    if ((num % i) == 0) return 0;
  }
  return 1;
}
int main() {
  cin >> p >> r;
  for (long long i = r; i > p; i--) {
    if (zhi(i)) {
      ans = i;
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
