#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
typedef long long ll;
typedef pair<int, int> P;

bool isprime(int n){
  if(n == 0 || n == 1) return false;
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  int N, p;
  while(cin >> N >> p && (N != -1 || p != -1)){
    vector<int> primes;
    vector<int> nums;
    while(primes.size() < 100){
      if(isprime(++N)) primes.push_back(N);
    }
    rep(i, (int)primes.size())rep(j, i + 1){
      nums.push_back(primes[i] + primes[j]);
    }
    sort(nums.begin(), nums.end());
    cout << nums[p-1] << endl;
  }
  return 0;
}