#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int i, j, p, y;
  cin >> p >> y;
  for (i = y; i > p; --i) {
    if (is_prime(i))
      return cout << i, 0;
    else {
      bool b = true;
      for (j = 2; j * j <= i && j <= p; ++j)
        if (i % j == 0) {
          b = false;
          break;
        }
      if (b)
        return cout << i, 0;
      else
        continue;
    }
  }
  cout << -1, 0;
}
