#include <bits/stdc++.h>
using namespace std;
int main() {
  bool visit[1000002] = {false};
  for (long long int i = 2; i <= 35000; i++) {
    if (visit[i] == false)
      for (long long int j = 2 * i; j <= 1000001; j += i) {
        visit[j] = true;
      }
  }
  long long int result = -1;
  vector<long long int> v;
  for (long long int i = 2; i < 1000001; i++)
    if (visit[i] == false) v.push_back(i);
  long long int a, b;
  cin >> a >> b;
  long long int id = 0;
  for (long long int i = b; i > a; i--) {
    for (long long int j = 0; j < v.size(); j++) {
      if (v[j] > a) break;
      if (i % v[j] == 0) {
        id = 1;
        break;
      }
    }
    if (id == 0) {
      result = i;
      break;
    }
    id = 0;
  }
  cout << result << "\n";
  return 0;
}
