#include <bits/stdc++.h>
using namespace std;
int p, y, ans;
int main() {
  cin >> p >> y;
  for (int i = y; i > p; i--) {
    int f = 1;
    for (int j = 2; j * j <= i && j <= p; j++) {
      if (i % j == 0) {
        f = 0;
        break;
      }
    }
    if (f) {
      ans = i;
      break;
    }
  }
  if (ans) {
    cout << ans;
  } else
    cout << -1;
  return 0;
}
