#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long p, y;
  cin >> p >> y;
  long long ans = -1;
  for (long long x = y; x > p; --x) {
    bool b = true;
    for (long long i = 2; i * i <= x; ++i)
      if (x % i == 0) {
        if (i <= p)
          b = false;
        else if (x / i <= p)
          b = false;
        break;
      }
    if (b) {
      ans = x;
      break;
    }
  }
  cout << ans;
  return 0;
}
