#include <bits/stdc++.h>
using namespace std;
int n, m, koo = -1;
int pansu(int a) {
  for (int i = 2; i * i <= a && i <= n; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = m; i > n; i--) {
    if (pansu(i)) {
      printf("%d", i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
