require 'prime'
primes = Prime.each(102000).to_a
loop do
    n, p = gets.split.map(&:to_i)
    break if n == -1 && p == -1
    pm = primes.select{|p| p > n}[0..p]
    p pm.product(pm).map{|a| a.sort}.uniq.map{|a,b| a + b}.sort[p - 1]
end