#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T multimod(T a, T b, T m) {
  T ans = 0;
  a %= m, b %= m;
  while (b) {
    if (b & 1) ans = m - ans > a ? (ans + a) : (ans + a - m);
    b >>= 1;
    a = (m - a) > a ? a + a : a + a - m;
  }
  return (T)ans;
}
void sc(int &a) { scanf("%d", &a); }
void sc(long long &a) { scanf("%lld", &a); }
void sc(double &a) { scanf("%lf", &a); }
void sc(int &a, int &b) { scanf("%d %d", &a, &b); }
void sc(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void sc(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void sc(int &a, int &b, long long &c) { scanf("%d %d %lld", &a, &b, &c); }
void sc(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void sc(string &str) { cin >> str; }
void sc(char *(str)) { scanf(" %s", str); }
void sc(char &c) { scanf(" %c", &c); }
int ind;
bool is[(200000 + 7)];
int prime[500000];
void sieve() {
  int i, j;
  prime[ind++] = 2;
  for (i = 3; i < (200000 + 7); i += 2) {
    if (!is[i]) {
      prime[ind++] = i;
      for (j = i * 2; j < (200000 + 7); j += i) is[j] = 1;
    }
  }
}
bool canDivide(int n, int p) {
  int sq = sqrt(n) + 5;
  for (int i = 0; i < ind && prime[i] <= sq && prime[i] <= p; i++) {
    if (n % prime[i] == 0) return true;
  }
  return false;
}
int main() {
  int i, j, k;
  int t, n, p, y, m, a, b, c;
  sieve();
  sc(p, y);
  for (; y > p; y--) {
    if (!canDivide(y, p)) {
      printf("%d\n", y);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
