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