#include <bits/stdc++.h>
using namespace std;
int x, y;
map<int, bool> dd;
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> x >> y;
  while (y > x) {
    bool have = 0;
    for (int i = (2); i <= (sqrt(y)); ++i)
      if (y % i == 0) {
        if (i <= x) {
          have = 1;
          break;
        }
      }
    if (!have) {
      cout << y;
      return 0;
    }
    --y;
  }
  cout << -1;
}
