#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int main(){
	
	int N = 200000;
	
	bool a[200000];
	
	for(int i = 0; i < N; i++){
		a[i] = true;
	}
	
	a[0] = false;
	a[1] = false;
	
	for(int i = 2; i < N; i++){
		if(a[i]){
			for(int j = i * 2; j < N; j += i){
				a[j] = false;
			}
		}
	}
	
	int P;
	
	while(true){
		
		cin >> N >> P;
		
		if(P == -1){
			break;
		}
		
		int primes[100];
		
		int count = 0;
		
		while(true){
			N++;
			if(a[N]){
				primes[count] = N;
				count++;
			}
			if(count == 100){
				break;
			}
		}
		
		vector<int> v;
		
		for(int i = 0; i < 100; i++){
			for(int j = i; j < 100; j++){
				v.push_back(primes[i] + primes[j]);
			}
		}
		
		sort(v.begin(), v.end());
		
		cout << v[P - 1] << endl;
		
	}
	
	return 0;
}