#include <bits/stdc++.h>
using namespace std;
long long n, m, k, g[2010], a[100003], f[2010], ansn, sum1, sum2;
bool make[200];
int main() {
  cin >> n >> m;
  bool see = false;
  for (int i = m; i > n; i--) {
    for (int j = 2; j <= min((long long)100000, n) and !see; j++)
      if (i % j == 0) {
        see = true;
      }
    if (!see) return cout << i, 0;
    see = false;
  }
  cout << "-1";
}
