#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long z, n;
    cin >> z >> n;
    if (n <= 100000000) {
      bool prime[n + 1];
      memset(prime, true, sizeof(prime));
      for (long long int p = 2; p * p <= n && p <= z; p++) {
        if (prime[p] == true) {
          for (long long int i = p * 2; i <= n; i += p) prime[i] = false;
        }
      }
      for (long long i = n; i > z; i--) {
        if (prime[i] == true) {
          cout << i;
          exit(0);
        }
      }
      cout << -1;
    } else {
      int f = 1;
      for (long long i = n; i > z; i--) {
        f = 1;
        for (long long k = 2; k <= z && k * k <= i; k++) {
          if (i % k == 0) {
            f = 0;
          }
        }
        if (f) {
          cout << i;
          exit(0);
        } else
          continue;
      }
      cout << -1;
    }
  }
  return 0;
}
