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

int main() {
	vector<bool>x( 200000, 1 );
	vector<long long int>prime;
	x[0] = x[1] = 0;
	for( size_t i = 0; i < 200000; i++ ) {
		if( x[i] ) {
			prime.emplace_back( i );
			long long int j = 2;
			while( i*j < 200000 ) {
				x[i*j] = 0;
				j++;
			}
		}
	}
	long long int N, M;
	while( cin >> N >> M, N != -1 && M != -1 ) {
		auto now = upper_bound( prime.begin(), prime.end(), N ) - prime.begin();
		vector<long long int >memo;
		for( size_t i = 0; i < 101; i++ ) {
			for( size_t j = i; j < 101; j++ ) {
				memo.emplace_back( prime[now + i] + prime[now + j] );
			}
		}
		sort( memo.begin(), memo.end() );
		//memo.erase( unique( memo.begin(), memo.end() ), memo.end() );
		cout << memo[M - 1] << endl;
	}
}