#include <bits/stdc++.h>
using namespace std;
int i;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool miillerTest(int d, int n) {
  int a = 2 + rand() % (n - 4);
  int x = power(a, d, n);
  if (x == 1 || x == n - 1) return true;
  while (d != n - 1) {
    x = (x * x) % n;
    d *= 2;
    if (x == 1) return false;
    if (x == n - 1) return true;
  }
  return false;
}
bool isPrime(int n, int k = 4) {
  if (n <= 1 || n == 4) return false;
  if (n <= 3) return true;
  int d = n - 1;
  while (d % 2 == 0) d /= 2;
  for (int i = 0; i < k; i++)
    if (miillerTest(d, n) == false) return false;
  return true;
}
int main() {
  int p, y, m = -1, c = 0;
  cin >> p >> y;
  for (int i = y; i > p; i--) {
    int f = 0;
    for (int j = 2; j < sqrt(i) + 1; j = j + 1) {
      if (i % j == 0) {
        if (j < p + 1) {
          f = 1;
          break;
        }
        if (i / j < p + 1) {
          f = 1;
          break;
        }
      }
    }
    if (f == 0) {
      m = i;
      break;
    }
  }
  cout << m;
}
