#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, m, a, o;
  scanf("%d%d", &n, &p);
  m = min(n, (int)(sqrt(p)));
  a = -1;
  for (int i = p; i > n; i--) {
    o = 0;
    for (int j = 2; j <= m; j++) {
      if (i % j == 0) {
        o = 1;
        break;
      }
    }
    if (!o) {
      a = i;
      break;
    }
  }
  printf("%d\n", a);
  return 0;
}
