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 = list(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]))

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 = list(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]))

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 = list(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]))

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 = list(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]))

-    choice = primes[init : init + 100] +    choice = primes[init : init + p]