#include <bits/stdc++.h>
using namespace std;
int t, n, m, ans, tot;
int pr[100005];
signed main() {
  int i, j, k, l, r, ca = 0;
  for (i = 3; i < 100000; i += 2) {
    if (pr[i]) continue;
    pr[++pr[0]] = i;
    for (j = i * 3; j < 100000; j += i * 2) pr[j] = 1;
  }
  scanf("%d%d", &n, &m);
  if (m % 2 == 0) m--;
  for (i = m; i > n; i -= 2) {
    k = 1;
    for (j = 1; j <= pr[0] && pr[j] <= n && pr[j] * pr[j] <= i; j++) {
      if (i % pr[j] == 0) {
        k = 0;
        break;
      }
    }
    if (k) return printf("%d\n", i), 0;
  }
  puts("-1");
  return 0;
}
