#include <bits/stdc++.h>
using namespace std;
int pcnt, p, y;
int minDiv(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return i;
    }
  }
  return x;
}
int main() {
  scanf("%d%d", &p, &y);
  for (int i = y; i > p; i--) {
    int x = minDiv(i);
    if (x > p) {
      printf("%d\n", i);
      return 0;
    }
    if (x == i) {
      break;
    }
  }
  printf("-1\n");
}
