#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
void solve() {
  long long p, y;
  cin >> p >> y;
  long long ans = -1;
  for (long long i = y; i > p; i--) {
    long long k = -1;
    for (long long j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        k = j;
        break;
      }
    }
    if (k == -1 || k > p) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  long long t = 1;
  while (t--) solve();
  return 0;
}
