#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, l, m, l1, n, s = 0, neg = 0, pos = 0, t, t1, r, w, q;
  scanf("%lld %lld", &n, &m);
  if (m == n) {
    printf("-1\n");
    return 0;
  }
  w = sqrt(m);
  for (i = m; i > n; i--) {
    for (j = 2; j <= w && j <= n; j++) {
      if (i % j == 0) {
        break;
      }
      if (j == w || j == n && i % j != 0) {
        printf("%lld\n", i);
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}
