#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np L, H = map(int, read().split()) U = 10 ** 5 + 10 is_prime = np.zeros(U, np.bool) is_prime[2] = 1 is_prime[3::2] = 1 for p in range(3, U, 2): if p * p >= U: break if is_prime[p]: is_prime[p * p:: p + p] = 0 primes = np.where(is_prime)[0] def solve(L, R): global primes primes = primes[primes ** 2 <= R] p = primes[-1] if p * p >= L: L = p * p n = R - L + 1 min_p = np.zeros(n, np.int64) for p in primes[::-1]: i = (-L) % p min_p[i::p] = p return L + np.where(min_p == min_p.max())[0][-1] print(solve(L, H))