#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define int long long

const int NN = 10000000;

int prime[NN];
bool is_prime[NN + 1];



int solve(int n)
{
	int p = 0;
	REP(i, n)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n ; i++){
		if (is_prime[i]){
			prime[p++] = i;
			for (int j = 2*i; j <= n; j+=i){
				is_prime[j] = false;
			}
		}
	}
	return p;
}

signed main(){
	solve(NN);

	while (1){

		vector<int> ar;	
		int a = 0;
		int N, P;
		cin >> N >> P;

		if (N == -1 && P == -1)break;

		REP(i, NN){
			if (prime[a] > N)break;
			a++;
		}

		REP(i, 100){
			for (int j = i; j < 100;++j){
				int x = prime[a + i] + prime[a + j];
				ar.push_back(x);
			}
		}

		sort(ar.begin(), ar.end());

		cout << ar[P - 1] << endl;

	}
	return 0;

}