#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
bool isp(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  int p, y;
  scanf("%d %d", &p, &y);
  int ans = 0;
  for (int i = y; i > p; i--) {
    if (isp(i)) {
      return !printf("%d\n", i);
    }
    int t = -1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        t = j;
        break;
      }
    }
    if (t > p) {
      return !printf("%d\n", i);
    }
  }
  puts("-1");
  return 0;
}
