#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> prime;
ll size = 1010101;
int main() {
  vector<bool> used(size);
  for (int i = 2; i < size; i++) {
    if (!used[i]) {
      prime.push_back(i);
      for (int j = 1; i * j < size; j++)
        used[i * j] = true;
    }
  }
  while (true) {
    int n, p;
    cin >> n >> p;
    if (n == -1)
      break;
    auto it = upper_bound(prime.begin(), prime.end(), n);
    vector<ll> ps;
    for (int i = 0; i < p; i++)
      for (int j = i; j < p; j++)
        ps.push_back((*(it + i)) + (*(it + j)));
    sort(ps.begin(), ps.end());
    cout << ps[p - 1] << endl;
  }
  return 0;
}
