import strutils,sequtils,algorithm proc CToI(c : char):int = return int(c) - int('0') var K = stdin.readline.parseInt N = stdin.readline.parseInt sosuu = newSeq[int](0) natu = newSeqWith(N + 1,true) k : int for i in 2..N: if natu[i]: k = i while k <= N: natu[k] = false k += i sosuu.add(i) var Nid,Kid : int H : seq[int] s : string flag = newSeqWith(10,false) rig,lef,ans,M : int Nid = sosuu.lowerBound(N) - 1 Kid = sosuu.lowerBound(K) if sosuu[^1] == N: Nid += 1 H = @[] for i in sosuu[Kid..Nid]: k = i while k >= 10: s = $k k = 0 for t in s: k += CToI(t) H.add(k) lef = 0 M = 0 for rig in 0..H.high: if flag[H[rig]] == false: flag[H[rig]] = true else: while flag[H[rig]] == true: flag[H[lef]] = false lef += 1 flag[H[rig]] = true if rig - lef + 1 >= M: ans = sosuu[Kid + lef] M = rig - lef + 1 if M == 7: break echo ans