#include <iostream>
#include <algorithm>
using namespace std;
bool prime[300005];

void init(void){
  for(int i = 0 ; i < 300005 ; i++){prime[i] = true;}
  prime[0] = false, prime[1] = false;
  for(int i = 2 ; i < 300005 ; i++){
    if(prime[i] == true){
      for(int k = 2 ; i * k < 300005 ; k++){
	prime[i * k] = false;
      }
    }
  }
}

int main(void){
    init();
    for(;;){
        int N, P;
        cin >> N >> P;
	if(N == -1 && P == -1){return 0;}
        int p[100];
        int ptr=0;
        for(int i = N + 1 ; ptr<100 ; i++){
            if(prime[i]){p[ptr] = i; ptr++;}
        }
        int sum[50*101]; ptr=0;
        for(int i = 0 ; i < 100 ; i++){
            for(int j = i ; j < 100 ; j++){
                sum[ptr] = p[i] + p[j]; ptr++;
            }
        }
	sort(sum, sum+5050);
        cout << sum[P-1] << endl;
    }
}

