#include <bits/stdc++.h>
using namespace std;

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	ll n, p;
	vector<int> prime;
	vector<bool> check(150000);
	
	check[1] = check[0] = true;
	REP(i, 2, 150000){
		if(!check[i]) prime.push_back(i);
		for(int j = 2; i * j < 150000; j++){
			check[i * j] = true;
		}
	}
	
	//rep(i, prime.size()) cout << prime[i] << endl;
	//return 0;
	
	
	while(cin >> n >> p){
		if(n == -1 && p == -1) break;
		
		auto it = upper_bound(prime.begin(), prime.end(), n);
		vector<ll> tmp(p*p);
		rep(i, p){
			auto it2 = it;
			rep(j, p){
				tmp[i*p+j] = (ll)(*it) + *it2;
				it2++;
			}
			it++;
		}
		
		SORT(tmp);
		cout << tmp[p-1] << endl;
		
	}
	
	
	// your code goes here
	return 0;
}