#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) { return *(int *) a - *(int *) b; }

int main() {
  while (1) {
    int N, P;
    scanf("%d %d", &N, &P);
    if (N == -1 && P == -1) break;
    int prime[1], primeSize = 0;
    for (int n = N + 1; primeSize < P; n++) {
      bool isPrime = n != 1;
      for (int i = 2; i < n; i++) isPrime &= n % i > 0;
      if (isPrime) prime[primeSize++] = n;
    }
    int primeSum[10000], primeSumSize = 0;
    for (int i = 0; i < primeSize; i++) {
      for (int j = i; j < primeSize; j++) primeSum[primeSumSize++] = prime[i] + prime[j];
    }
    qsort(primeSum, primeSumSize, sizeof(int), comp);
    printf("%d\n", primeSum[P - 1]);
  }
}

