def Eratosthenes(N): #N以下の素数のリストを返す #iが素数のときis_prime_list[i]=1,それ以外は0 N+=1 is_prime_list = [True]*N # is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化 # for j in range(4,N,2): is_prime_list[j] = False m = int(N**0.5)+1 for i in range(3,m,2): if is_prime_list[i]: is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,N,2) if is_prime_list[i]] # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read #a,b,c = map(int,readline().split()) k = int(input()) n = int(input()) primes = [i for i in Eratosthenes(2*10**5) if k <= i <= n] res = [i%9 for i in primes] idx = 0 val = 0 n = len(res) s = set() for i in range(n): cnt = 0 j = i while j < n and res[j] not in s: cnt += 1 s.add(res[j]) j += 1 #print(i,j,s,val) if val <= j-i: val = j-i idx = i s.clear() #print(idx) print(primes[idx])