MAX =150000
prime = Array.new(MAX,true)
primes = Array.new
prime[0]=prime[1]=false
(2..MAX).each do |i|
  if prime[i]
    primes <<i
    (i+i).step(MAX,i) do |j|
      prime[j]=false
    end
  end
end
loop do
  n,p= gets.split.map(&:to_i)
  break if n==-1 && p == -1
  arr=primes.select{|x| x>n}.take(p+1)
  ans=[]
  (0...arr.size).each do |i|
    (i...arr.size).each do |j|
      ans << arr[i]+arr[j]
    end
  end
  ans.sort!
  p ans[p-1]
end