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(200001)]
prime[0] = False
prime[1] = False
p = 2
while p * p <= 200000:
    if prime[p]:
        for i in range(p * 2, 200001, p):
            prime[i] = False
    p += 1

while True:
    N, P = map(int, input().split())
    if N < 0:
        exit()
    li = []
    for i in range(N + 1, N + 10001):
        if prime[i]:
            li.append(i)
    li.sort()
    ans = []
    for i in range(100):
        for j in range(i, 100):
            ans.append(li[i] + li[j])
    print(sorted(ans)[P - 1])

Python: def prime(n):
    primes = [True] * (n+1)
    primes[0] = False
    primes[1] = False

    for i in range(2, int(n**0.5)+1):
        if not primes[i]:
            continue

        for j in range(i*2, n+1, i):
            primes[j] = False

    return [i for i in range(n+1) if primes[i]]


while True:
    N, P = map(int, input().split())  # Nより大きい素数, 和の小さな方がP番目

    if N == -1:
        break

    prime_numbers = [i for i in prime(120000) if i > N]

    hoge = []
    for i in range(P+1):
        for j in range(i, P+1):
            hoge.append(prime_numbers[i] + prime_numbers[j])

    hoge.sort()

    print(hoge[P-1])

Python: def eratosthenes(n):
    length = 150000
    ret = []
    flag = [True] * length
    for i in range(2, length):
        if flag[i]:
            if n < i:
                ret.append(i)
            for j in range(i, length, i):
                flag[j] = False
        if len(ret) > 50:
            break
    return ret


if __name__ == "__main__":
    while True:
        N, P = map(int, input().split())
        if N == -1 and P == -1:
            break
        ret = eratosthenes(N)
        sosu_add = []
        for i in range(len(ret)):
            for j in range(i, len(ret)):
                sosu_add.append(ret[i] + ret[j])
        sosu_add.sort()
        print(sosu_add[P - 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
    n=bisect.bisect_right(pr,n)
    print(sorted([pr[i]+pr[j] for i in range(n,n+p) for j in range(i,n+p)])[p-1])

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

def main():
    rr = []

    pr = Prime(10**11)

    while True:
        n,p = LI()
        if n < 0 and p < 0:
            break
        t = []
        i = n
        while len(t) < p:
            i += 1
            if pr.is_prime(i):
                t.append(i)

        u = []
        for i in range(p):
            for j in range(i,p):
                u.append(t[i]+t[j])
        u.sort()
        rr.append(u[p-1])

    return '\n'.join(map(str, rr))


print(main())

Python: n=[i for i in range(100272)]
n[:2]=[0,0]
for i in range(2, 100272//2):
    if n[i]==i:n[i*2::i]=[0 for e in range(len(n[i*2::i]))]
while True:
    M,P=[int(i) for i in input().split()]
    if M==-1 and P==-1:break
    p=list(filter(lambda x:x!=0,n[M+1:]))[:25]
    l=[]
    for i in range(len(p)):
        for j in range(i+1):
            l.append(p[i]+p[j])
    print(sorted(l)[P-1])

Python: def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):  # 確かめるのはnの平方根までで大丈夫
        if not is_prime[i]:  # すでにfalseなら次のiへ
            continue
            """
            bool(not False)はTrueになる
            """
        for j in range(i * 2, n + 1, i):  # iずつ大きくなる(つまりiの倍数をみる)
            is_prime[j] = False  # i自身を除くiの倍数を全てFalseにする
    return [i for i in range(n + 1) if is_prime[i]]  # Trueのものだけ列挙して返す


while 1:
    N, P = map(int, input().split())
    if N == -1:
        exit()
    prime_numbers = [i for i in primes(120000) if i > N]

    prime_wa = []
    for i in range(P+1):
        for j in range(i, int(P+1)):
            prime_wa.append(prime_numbers[i]+prime_numbers[j])

    prime_wa.sort()

    print(prime_wa[P-1])