#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 1000000
using namespace std;

int main(){
  bool a[MAX];
  vector<int> v;
  for(int i=0;i<MAX;i++) a[i] = true;
  a[0] = a[1] = false;
  for(int i=2;i<MAX;i++){
    if(a[i]){
      v.push_back(i);
      for(int j=i+i;j<MAX;j+=i) a[j] = false;
    }
  }

  int n,p;
  while(cin >> n >> p){
    if(n == -1 && p == -1) break;

    vector<int> s;
    for(int i=0;i<v.size();i++){
      if(v[i] > n){
	for(int j=i;j<i+100;j++){
	  if(j >= v.size()) break;
	  for(int k=j;k<i+100;k++){
	    if(k >= v.size()) break;
	    s.push_back(v[j]+v[k]);
	  }
	}
	break;
      }
    }

    sort(s.begin(),s.end());

    cout << s[p-1] << endl;
  }
  return 0;
}