#include <bits/stdc++.h>
using namespace std;
bool any(unsigned long long int x, unsigned long long int y) {
  if (x % y == 0) return 1;
  for (unsigned long long int i = 2;
       i <= min(y, (unsigned long long int)sqrt(x)); i++) {
    if (x % i == 0) return 1;
  }
  return 0;
}
void solve() {
  long long int p, y;
  cin >> p >> y;
  for (long long int i = y; i >= p; i--) {
    if (any(i, p))
      continue;
    else {
      cout << i << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
