#include <bits/stdc++.h>
using namespace std;
void Mohamed_Galal() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
void pause() {}
int p, y;
bool Is_Prime(long long n) {
  if (n < 2) return false;
  for (long long i = 2; i <= sqrt(n) && i <= p; i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  Mohamed_Galal();
  cin >> p >> y;
  for (long long i = y; i > p; i--) {
    if (Is_Prime(i)) return cout << i << endl, 0;
  }
  cout << -1 << endl;
  pause();
  return 0;
}
