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

#define PRIME_TABLE_SIZE 1000000
#define P_MAX 100
#define UNKNOWN -1

char is_prime[PRIME_TABLE_SIZE];
int next_prime[PRIME_TABLE_SIZE];

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

void prime_table_init()
{
    int i, j;

    /* sieve */

    is_prime[0] = is_prime[1] = 0;
    for(i = 2; i < PRIME_TABLE_SIZE; i++)
        is_prime[i] = 1;

    i = 2;
    while(i < PRIME_TABLE_SIZE)
    {
        for(j = i * 2; j < PRIME_TABLE_SIZE; j += i)
            is_prime[j] = 0;

        /* search for the next prime */
        for(i++; !is_prime[i] && PRIME_TABLE_SIZE < i; i++);
    }

    for(i = UNKNOWN, j = PRIME_TABLE_SIZE - 1; j >= 0; j--)
    {
        next_prime[j] = i;
        if(is_prime[j]) i = j;
    }
}

int main(void)
{
    int n, p, i, j, k, primes[P_MAX], sums[P_MAX * P_MAX];

    prime_table_init();

    while(scanf("%d %d", &n, &p), n != -1)
    {
        for(i = 0, j = next_prime[n]; i < p; i++, j = next_prime[j])
            primes[i] = j;
        for(i = k = 0; i < p; i++)
            for(j = 0; j <= i; j++, k++)
                sums[k] = primes[i] + primes[j];
        qsort(sums, k, sizeof(int), comp_ints);
        printf("%d\n", sums[p - 1]);
    }

    return 0;
}