#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	const int MAX = 120000;
	const vector<int> primes = sieve(MAX);
	for(int n, p; cin >> n >> p, n != -1;) {
		const int start = upper_bound(primes.begin(), primes.end(), n) - primes.begin();
		vector<int> nums;
		nums.reserve(6000);
		for(int i = start; i < start + 100; ++i)
			for(int j = i; j < start + 100; ++j)
				nums.push_back(primes[i] + primes[j]);

		sort(nums.begin(), nums.end());
		cout << nums[p - 1] << endl;
	}

	return EXIT_SUCCESS;
}