#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int M = 100005;
const int MOD = 1e9 + 7;
int main() {
  int p, y;
  scanf("%d %d", &p, &y);
  for (int i = y; i > p; --i) {
    long long t;
    for (t = 2; t * t < i; ++t)
      if (i % t == 0 && t <= p) break;
    if (t * t >= i) {
      if (t * t == i && t <= p) continue;
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
