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