Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, p := io.NextInt(), io.NextInt()
		if n == -1 {
			break
		}
		isPrime := SieveOpt(200000)
		prime := make([]int, p)
		cnt := 0
		if n < 2 {
			prime[0] = 2
			cnt++
		}
		for i := (n + 1) / 2; i < len(isPrime) && cnt < p; i++ {
			if isPrime[i] == true {
				prime[cnt] = 2*i + 1
				cnt++
			}
		}
		comb := make([]int, 0, p*p)
		for i := 0; i < p; i++ {
			for j := i; j < p; j++ {
				comb = append(comb, prime[i]+prime[j])
			}
		}
		sort.Ints(comb)
		io.Println(comb[p-1])
	}
}

func SieveOpt(x int) []bool {
	flags := make([]bool, x/2) // flags[i] := 2*j+1 is prime
	for i := 1; i < x/2; i++ {
		flags[i] = true
	}
	sqrtXi := int(math.Ceil(math.Sqrt(float64(x)))) / 2
	for i := 1; i < sqrtXi; i ++ {
		if !flags[i] {
			continue
		}
		for j := 2 * i * (i + 1); j < x/2; j += 2*i + 1 {
			flags[j] = false
		}
	}
	return flags
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: prime = [True for i in range(160001)]
prime[0] = prime[1] = False
for i in range(2, 401):
    if prime[i]:
        for j in range(2, 160000 // i + 1):
            prime[i * j] = False

while True:
    n, p = map(int, input().split())
    if n == p == -1:
        break

    pli = list()
    for i in range(p):
        while True:
            n += 1
            if prime[n]:
                pli.append(n)
                break

    numli = list()
    for x in range(p):
        for y in range(x, p):
            numli.append(pli[x] + pli[y])

    numli.sort()
    print(numli[p - 1])

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
import itertools

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

primeTable = sieve_of_erastosthenes(10**6)

while True:
    N,P = map(int,input().split(" "))
    if N == -1 and P == -1:
        break
    start = N+1
    while primeTable[start] is False:
        start += 1
    prime_list = []
    count = 0
    i = 0
    while count != P:
        if primeTable[start + i]:
            prime_list.append(start+i)
            count += 1
        i += 1
    print(sorted([sum(t) for t in itertools.combinations_with_replacement(prime_list,2)])[P-1])

Python: from bisect import bisect_right as br
from itertools import combinations_with_replacement as cwr

MAX = 110000
ROOT = 340
tf = [True] * MAX
tf[0] = tf[1] = False
for i in range(2, ROOT + 1):
  if tf[i]:
    for j in range(i * i, MAX, i):
      tf[j] = False
primes = [i for i in range(MAX) if tf[i]]

while True:
  n, p = map(int ,input().split())
  if n == -1:break
  init = br(primes, n)
  choice = primes[init:init+p]
  lst = []
  for i, j in cwr(choice, 2):
    lst.append(i + j)
  lst.sort()
  print(lst[p - 1])

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
import itertools

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

primeTable = sieve_of_erastosthenes(10**6)

while True:
    N,P = map(int,input().split(" "))
    if N == -1 and P == -1:
        break
    start = N
    while primeTable[start] is False:
        start += 1
    prime_list = []
    count = 0
    i = 0
    while count != P:
        if primeTable[start + i]:
            prime_list.append(start+i)
            count += 1
        i += 1
    print(sorted([sum(t) for t in itertools.combinations_with_replacement(prime_list,2)])[P-1])

Python: import bisect
MAX_N = 120000
sieve = [0,0] + [1] * MAX_N
n = 2
primes = []
while n*n < MAX_N:
    if sieve[n]:
        primes.append(n)
        for m in range(2*n,MAX_N,n):
            sieve[m] = 0
    n += 1
for m in range(n,MAX_N):
    if sieve[m]: primes.append(m)

while True:
    N,P = map(int,input().split())
    if N == -1: break
    i = bisect.bisect_right(primes, N)
    li = []
    for p1 in range(i,i+P):
        for p2 in range(p1,i+P+1):
            li.append(primes[p1] + primes[p2])
    print(sorted(li)[P-1])

Python: from itertools import *
N=101198;n=range(N);a=list(n);a[1]=0
for i in range(2,int(N**.5)+1):a[i*2::i]=[0]*len(a[i*2::i])

for e in iter(input, '-1 -1'):
    qN, qP = map(int, e.split())
    p=[x for x in a[qN+1:]if x][:qP+1]
    print(sorted(p[i]+p[j]for i in range(qP)for j in range(i,qP))[qP-1])

Python: import bisect
pr=[]
for i in range(2,110000):
    for j in range(2,int(i**0.5)+1):
        if not i%j:break
    else:pr+=[i]
while 1:
    n,p=map(int,input().split())
    if n<0:break
    a=bisect.bisect_right(pr,n)
    print(sorted([pr[i]+pr[j] for i in range(a,a+p) for j in range(i,a+p)])[p-1])

Python: def eratosthenes(n):
    prime_table = [False,False,True]+[False if i%2!=0 else True for i in range(n-2)]
    i=3
    pn=[2]
    while i*i<=n:
        if prime_table[i]:
            j=i*i
            pn.append(i)
            while j<=n:
                prime_table[j]=False
                j+=i
        i+=2
    for j in range(i,n+1):
        if prime_table[j]:
            pn.append(j)
    return pn

prime_numbers=eratosthenes(200000)
while 1:
    n,p=map(int,input().split())
    if n==-1:
        break
    i=0
    while prime_numbers[i]<=n:
        i+=1
    d=[]
    for j in range(i,i+30):
        for k in range(j,i+30):
            d.append(prime_numbers[j]+prime_numbers[k])
    d.sort()
    print(d[p-1])