#include<stdio.h>
int prime[1300001];

void isprime(void){
    int i,j,n,c;

    for(i = 4;i<1300001;i += 2)prime[i] = 1;

    for (i = 3;i * i <= 1300001;i += 2){
        if (prime[i] == 0){
            for (j = i + i; j <= 1300001; j += i){
                prime[j] = 1;
            }
        }
    }
}

int main(void){
    int n,i,a=0;
    int p,j,k;
    isprime();
    
    while (scanf("%d%d",&n,&p),n==-1&&p==-1){
a=0;
        for(i = (n+1)*2;;i++){
for(j = n+1;j < i;j++){
 for(k = j;j+k <= i;k++){
  if(j+k == i){
   if(prime[j]*prime[k]){
    a++;
    if(a==p){
     printf("%d\n",i);
goto a;
    }
   }
  }
 }
}
        }
a:
    }
     
    return (0);
}