#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
bool prime[MAX];
signed
main(){
	vector<int> pnum;
	for(int i=0;i<MAX;i++)
		prime[i] = true;
	prime[1] = false;
	for(int i=2;i<MAX;i++)
	{
		if(prime[i])
		{
			pnum.push_back(i);
			for(int j=2*i;j<MAX;j+=i)
				prime[j] = false;
		}
	}

	int n,p;
	while(cin >> n >> p)
	{
		if(n==-1 and p==-1) break;
		int cnt = 0;
		while(1)
		{
			if(pnum[cnt]>n) break;
			else cnt++;
		}
		vector<int> ans;
		for(int i=cnt;i<cnt+p;i++)
		{
			for(int j=i;j<cnt+p;j++)
			{
				ans.push_back(pnum[i]+pnum[j]);
			}
		}
		sort(ans.begin(),ans.end());
		cout << ans[p-1] << endl;
	}
}
