#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define M 20000
int c[N], primes[M], v[M];

int comp(const void* a, const void* b) { return *((int*)a)>*((int*)b); }
int main(void)
{
    int i, j, k, n, p, pc;
    for(pc=0,i=2;i<N;++i) if (!c[i]) {
        primes[pc++]=i;
        for(j=i+i;j<N;j+=i) c[j]=1;
    }

    while (scanf("%d%d", &n, &p), ~n) {
        int x;
        for(k=0;k<pc;++k) if (primes[k]>n) break;
        x=0;
        for(i=k;i<k+100;++i) for(j=i;j<k+100;++j)
            v[x++]=primes[i]+primes[j];
        qsort(v, x, sizeof(int), comp);
        printf("%d\n", v[p-1]);
    }
    return 0;
}