function main(input) { let [N] = getIntegers(input, " "); let [K] = getIntegers(input, " "); let prime = primeList(N, K); let hash = prime.map(x=>x%9); let idx = solve(hash); console.log(prime[idx]); } function solve(L) { let i=0, j=0, max=0, maxI=0; let LL = []; while(j < L.length) { let idx = LL.indexOf(L[j], i); if(idx >= 0) i=idx+1; LL.push(L[j]); j++; if(max <= j-i) { max = j-i; maxI = i; } } return maxI; } function primeList(N, K) { let list = new Array(K+1).fill(true); list[0] = false; list[1] = false; for(let i=2; i<=Math.sqrt(K); i++) { if(list[i] == true) { for(let j=i*2; j<=K; j+=i) { list[j] = false; } } } let out = []; for(let i=2; i= N) out.push(i); } return out; } //-- functions --------------------------------------------------------------- function getIntegers(l, s) {return s === undefined ? l.map(x=>Number(x)) : l.shift().split(s).map(x=>Number(x))} main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));