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: def pri(k):
    if k==1:return False
    elif k==2: return True
    for i in range(2,int(k**0.5)+1):
        if k%i==0:
            return False
    return True
while True:
    n,p=map(int,input().split())
    if n==-1:
        exit()
    lprime=[]
    while len(lprime)!=p:
        n+=1
        if pri(n):
            lprime.append(n)
    lans=[]
    le=len(lprime)
    for k1 in range(le):
        for k2 in range(k1,le):
            lans.append(lprime[k1]+lprime[k2])
    lans.sort()
    print(lans[p-1])

Python: from bisect import bisect_left

# n >= 6
def sieve_fast(n):
    correction = (n%6>1)
    n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
    sieve = [True] * (n//3)
    sieve[0] = False
    for i in range(int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      ((k*k)//3)      ::2*k]=[False]*((n//6-(k*k)//6-1)//k+1)
        sieve[(k*k+4*k-2*k*(i&1))//3::2*k]=[False]*((n//6-(k*k+4*k-2*k*(i&1))//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

ps = sieve_fast(200010)
while True:
  N,P = map(int,input().split())
  if N < 0:
    break
  pos = bisect_left(ps,N+1)
  L = []
  for i in range(110):
    for j in range(i,110):
      L.append(ps[pos+i]+ps[pos+j])
  L.sort()
  print(L[P-1])

Python: import sys
from math import sqrt
from bisect import bisect

inf = 1<<30

def solve():
    primes = eratos(2 * 10**5)

    while 1:
        N, P = map(int, sys.stdin.readline().split())

        if N == P == -1:
            return

        j = bisect(primes, N)

        lprimes = primes[j:j + 100]

        made = []

        for i in range(100):
            for j in range(i, 100):
                made.append(lprimes[i] + lprimes[j])

        made.sort()

        ans = made[P - 1]

        print(ans)


def eratos(n):
    s = [True] * n
    s[0] = s[1] = False

    for p in range(2, int(sqrt(n)) + 1):
        if s[p]:
            for q in range(p*p, n, p):
                s[q] = False

    return [i for i in range(2, n) if s[i]]

if __name__ == '__main__':
    solve()

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+100]
  lst = []
  for i, j in cwr(choice, 2):
    lst.append(i + j)
  lst.sort()
  print(lst[p - 1])

Python: sieve = [True] * 110000
primes = []
for i in range(2, 110000):
    if sieve[i] == True:
        primes.append(i)
        for j in range(2*i, 110000, i):
            sieve[j] = False

while True:
    n, p = map(int, input().split())
    if n == -1 and p == -1: break
    cnt = 0
    for i in primes:
        if n < i: 
            break
        else: 
            cnt += 1
    psum = sorted([primes[i]+primes[j] for j in range(cnt, cnt+p) for i in range(j, cnt+p)])
    print(psum[p-1])

Python: 
primes = [True] * (150000)
primes[0] = primes[1] = False
for i in range(2, int(len(primes)**0.5)+1):
	if primes[i]:
		for j in range(i*2, len(primes), i):
			primes[j] = False

def m(n, p):
	ns = []
	for i in range(n+1, n+p+3000):
		if primes[i]: ns.append(i)
	r = []
	for i in range(len(ns)):
		for j in range(i, len(ns)):
			r.append(ns[i]+ns[j])
	return sorted(r)[p-1]

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