import Data.List

main = interact $ unlines . map (show . matsuzaki . map read . words) . init . lines

matsuzaki [n,p] = last . take p . sort $[p1+p2 | p1<-primes', p2<-primes', p1<=p2]
 where primes' = take p (dropWhile (<=n) primes)

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]