#include <stdio.h>
#define INF 200001

int main (void){
    int N, P;
    int count;
    int i, j;
   int ip;
    int eratos[INF]={};//0???true
    int memo;
    eratos[1]=1;
    for(i=2;i*i<INF;i++){
        for(j=2;i*j<INF;j++){
            eratos[i*j] = 1;
        }
    }
    while(1){
        scanf("%d %d",&N,&P);
        if(N == -1 && P == -1)
            break;
        
        count = 0;

        for(i = N+1;i<INF;i++){
            if(!eratos[i]){
                count++;
                if(count == P)
                    memo = i+i;
                ip = i;
                for(ip;ip<INF;ip++){
                    if(!eratos[i]){
                        count++;
                        if(count == P)
                            memo = i+ip;
                        break;
                    }
                }
            }
        }
        printf("%d",memo);
    }

    return 0;
}