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

int main(){
  int n,p;

  while(cin>>n>>p&&n!=-1&&p!=-1){
    vector<int> prime;

    if(n<=3){
      n=5;
      prime.push_back(2);
      prime.push_back(3);
      prime.push_back(5);
    }
    for(int i=n+1;i<=101000;i++){
      if(prime.size()==200) break;
      for(int j=2;j<=(int)sqrt(i);j++){
        if(i%j==0) break;
        if(j==(int)sqrt(i)){
          prime.push_back(i);
        }
      }
    }

    vector<int> sum;
    for(int i=0;i<prime.size();i++){
      for(int j=i;j<prime.size();j++){
 //       if(n==100000) cout << prime[i] << " + " << prime[j] << endl;
        sum.push_back(prime[i]+prime[j]);    
      }
    }

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

  return 0;
}