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

const int N = 5000000;
bool prime[N];
int main() {
    for (int i=0; i<N; ++i) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for (int i=2; i<N; ++i) {
        if (prime[i])
            for (int j=i*2; j<N; j+=i)
                prime[j] = 0;
    }
    vector<int> v;
    for (int i=0; i<N; ++i) if (prime[i]) v.push_back(i);
    
    int n, p;
    while(cin>>n>>p, n!=-1) {
        int a = upper_bound(v.begin(), v.end(), n) - v.begin();
        vector<int> ans;
        for (int i=a; i<a+100; ++i) {
            for (int j=a; j<=i; ++j) {
                ans.push_back(v[i]+v[j]);
            }
        }
        sort(ans.begin(), ans.end());
        //for (int i=0; i<100; ++i) cout << ans[i] << " ";cout <<endl;
        cout << ans[p-1] << endl;
    }
}