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