// Aizu 2150: Matsuzaki Number
// 2017.9.20 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MAX  101300
#define SQRT 318     // sqrt(MAX)
char prime[MAX + 3], *p, *q, *pmax = prime + MAX;

int a[105], s[10005];

int cmp(int *a, int *b) { return *a - *b; }

void mkprime()
{
	int k;
	prime[1] = 1;
//	for (p = prime + 4; p <= pmax; p += 2) *p = 1;
	for (k = 3, p = prime + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
}

int main()
{
	int n, p, i, j, k;

	mkprime();
	while (scanf("%d%d", &n, &p) && p) {
		if (n < 2) a[0] = 2, k = 1, i = 3;
		else k = 0, i = n + 1 + (n & 1);
		for ( ; k < p; i += 2) if (!prime[i]) a[k++] = i;
		for (k = 0, i = 0; i < p; i++) for (j = i; j < p; j++) 
			s[k++] = a[i] + a[j];
		qsort(s, k, sizeof(int), cmp);
		printf("%d\n", s[p-1]);
	}
	return 0;
}