#include <bits/stdc++.h>
using namespace std;
int main() {
  int p, y;
  cin >> p >> y;
  if (p == y) {
    cout << -1;
    exit(0);
  }
  for (int i = (y); i >= (p + 1); --i) {
    int sf = i;
    for (int j = 2; j <= sqrt(i); j++)
      if (i % j == 0) {
        sf = j;
        break;
      }
    if (sf > p) {
      cout << i;
      exit(0);
    }
  }
  cout << -1;
}
