//
//  main.c
//  Matsuzaki Number
//
//  Created by x15071xx on 2016/06/16.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>
#include <math.h>

#define NUM 150000


int find_i (int hurui[],int x){
    int i;
    
    for (i=x; i<NUM; i++) {
        if (hurui[i] == 1) {
            break;
        }
    }
    
    return i;
}

int main(int argc, const char * argv[]) {
    
    int hurui[NUM];
    int i,j;
    for (i=0; i<NUM; i++) {
        hurui[i] = 1;
    }
    hurui[0] = 0;
    hurui[1] = 0;
    
    for (i=2; i<sqrt(NUM); i++) {
        if (hurui[i] == 1) {
            for (j=i*2; j<NUM; j+=i) {
                hurui[j] = 0;
            }
        }
    }
    while (1) {
        
        int n=0,p=0,tmp=0;
        
        scanf("%d %d",&n,&p);
        
        if (n==-1 && p==-1) {
            break;
        }
        
        int count_p=0,pp=0,num_array[101],x=0,count_num=0,y=0,k=0;
        for (i=0; i<101; i++) {
            num_array[i]=0;
        }
        //n????????§????????????????´???°???
        x = find_i(hurui, n+1);
        for (i=n+1; count_num<p; i=y+1) {
            y = find_i(hurui, i);
            num_array[count_num] = x + y;
            count_num++;
        }
        
        count_p = num_array[p-1];
        
        for (i=x+1; i<count_p; i=x+1) {
            x = find_i(hurui, i);
            for (j = i; pp < count_p; j=y+1) {
                y = find_i(hurui, j);
                pp= x + y;
                num_array[count_num]=pp;
                //?????????????????????????????\??????
                k = count_num;
                while (num_array[k] < num_array[k-1]) {
                    tmp = num_array[k];
                    num_array[k] = num_array[k-1];
                    num_array[k-1] = tmp;
                    k--;
                }
                if (count_num != 101) {
                    count_num++;
                }
                
            }
            count_p=num_array[p-1];
            pp=0;
            int z = find_i(hurui, i+1);
            if (count_p < z*2) {
                break;
            }
            
        }
        printf("%d\n",num_array[p-1]);
    }
        
    
    
    
    return 0;
}