#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, y;
  cin >> p >> y;
  long long x = -1;
  bool valid = true;
  for (int i = y; i > p; i--) {
    valid = true;
    for (int j = 2; j <= min((long long)sqrt(i), p); j++) {
      if (i % j == 0) {
        valid = false;
        break;
      }
    }
    if (valid) {
      x = i;
      break;
    }
  }
  cout << x;
  return 0;
}
