#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool so[10000001];

int main() {

  so[0] = so[1] = 1;
  for(int i=2;i*i<=10000000;i++){
    if(so[i] == 0) {
      for(int j=2;j<=10000000/i;j++) so[i*j] = 1;
    }
  }

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

    int cnt = 0;

    int a[101] = {};
    for(int i=n+1;cnt<=p;i++) if(so[i] == 0) a[cnt] = i,cnt++;
    


    int c =0;
    bool flg[101][101];
    for(int i=0;i<=p;i++)
      for(int j=0;j<=p;j++) flg[i][j] = 0;
    vector <int> b;
    for(int i=0;i<=p;i++)
      for(int j=0;j<=p;j++) {
	if(flg[i][j] == 1) continue;
	flg[i][j] = 1;
	flg[j][i] = 1;
	int sum = a[i]+a[j];
	b.push_back(sum);
	c++;
      }

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

    // for(int i=0;i<p;i++) cout << b[i] <<endl;
    cout << b[p-1] <<endl;
  }
  return 0;
}
       