#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;
  cin >> p >> y;
  for (long long i = 0; i < 305; i++) {
    for (long long j = y - i; j > p; j--) {
      vector<long long> div;
      bool pos = 1;
      for (long long k = 2; k <= sqrt(j); k++) {
        if (j % k == 0 && k <= p) {
          pos = 0;
          break;
        }
      }
      if (pos) {
        cout << j;
        return 0;
      }
    }
  }
  cout << (-1);
  return 0;
}
