#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  long long p, y;
  cin >> p >> y;
  int flag = 1;
  for (long long j = y; j > p; j--) {
    flag = 0;
    for (long long k = 2; k <= p && k * k <= j; k++) {
      if (j % k == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << j;
      return 0;
    }
  }
  cout << -1;
}
