#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll mod = 1000000007;
const ll M = 1000000000000000000ll;
inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); }
inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); }
inline ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); }
inline ll power(ll n, ll x) {
  ll p = 1;
  while (x != 0) {
    if (x % 2 == 0) {
      n = mult(n, n);
      x = x / 2;
    }
    p = mult(p, n);
    x--;
  }
  return p;
}
ll lets(ll n, ll p) {
  ll fl = 1;
  if (n == 1) fl = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n = n / i;
      if (i <= p) fl = 0;
    }
  }
  if (n >= 2) {
    if (n <= p) fl = 0;
  }
  return fl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll p, y, fl = 1;
  cin >> p >> y;
  for (ll i = y; i > p; i--) {
    if (lets(i, p) == 1) {
      cout << i << "\n";
      fl = 0;
      break;
    }
  }
  if (fl == 1) cout << -1 << "\n";
}
