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