#include <bits/stdc++.h>
using namespace std;
int p, y;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> p >> y;
  int ans = -1;
  for (int i = y; i > p; i--) {
    bool isAns = true;
    for (int j = 2; j <= p && 1LL * j * j <= i; j++) {
      if (i % j == 0) {
        isAns = false;
        break;
      }
    }
    if (isAns) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
