import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np K,N = map(int,read().split()) def make_prime(U): is_prime = np.zeros(U,np.bool) is_prime[2] = 1 is_prime[3::2] = 1 M = int(U**.5)+1 for p in range(3,M,2): if is_prime[p]: is_prime[p*p::p+p] = 0 return is_prime, is_prime.nonzero()[0] _,primes = make_prime(N + 100) primes = primes[(K <= primes) & (primes <= N)] H = 1<<(primes % 9) H = np.append(H,[1023] * 10) Hset = [H] for _ in range(10): Hset.append(Hset[-1][:-1] | Hset[-1][1:]) for i,H in enumerate(Hset,1): popcount = np.zeros_like(H) for j in range(20): popcount += (H >> j)&1 is_ok = popcount[:len(primes)] == i if not np.any(is_ok): break answer = (primes * is_ok).max() print(answer)