#include <bits/stdc++.h>
using namespace std;
int vis[2000100];
int main() {
  int p, y;
  cin >> p >> y;
  bool found = 0;
  int ans = -1;
  for (int i = y; i > p; i--) {
    bool valid = 0;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        if (min(j, i / j) <= p) {
          valid = 1;
          break;
        }
      }
    }
    if (!valid) {
      found = 1;
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}
