#include <iostream>
#include <vector>
#include <queue>
#define ERA_MAX 1000000
#define ROO_MAX 316
using namespace std;

bool Eratos[ERA_MAX];

int M(int N, int P)
{
	priority_queue<int> pq;
	vector<int> vec(P);
	for (int i = 0, n = N + 1; i < P; n++) {
		if (Eratos[n]) {
			vec[i] = n;
			i++;
		}
	}
	for (int i = 0; i < P; i++) {
		for (int j = i; j < P; j++) {
			pq.push(-(vec[i] + vec[j]));
		}
	}
	for (int i = 0; i < P - 1; i++)
		pq.pop();
	return -pq.top();
}

int main()
{
	int N, P;
	Eratos[0] = Eratos[1] = false;
	for (int i = 2; i < ERA_MAX; i++) {
		Eratos[i] = true;
	}
	for (int i = 2; i < ROO_MAX; i++) {
		for (int j = i * 2; j < ERA_MAX; j += i) {
			Eratos[j] = false;
		}
	}
	while (cin >> N >> P, N != -1 || P != -1) {
		cout << M(N, P) << endl;
	}
	return 0;
}