#include <bits/stdc++.h>
using namespace std;
bool checkprime(int p, int N) {
  int count = 0;
  int i = 1;
  for (i = 1; i * i <= N and i <= p; ++i) {
    if (N % i == 0) {
      if (i * i == N)
        count++;
      else
        count += 2;
    }
  }
  if (count == 2) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int p, y;
  cin >> p >> y;
  bool breaked = false;
  for (int i = y; i > p; i--) {
    if (checkprime(p, i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
