#include <stdio.h>
#define MAX 200000


int isPrime[MAX];
int N,P;

void solve(){
	int i,j,n,p=0;
	for(n=2*N+1;;n++){
		for(i=N+1;i<n;i++){
			for(j=i;i+j<=n;j++){
				if(i+j==n&&isPrime[i]&&isPrime[j]){
					p++;
					if(p==P){
						printf("%d\n",n);
						return;
					}
				}
			}
		}
	}
}

int main(void){
	int i,j;
	for(i=2;i<MAX;i++)isPrime[i]=1;
	for(i=2;i<MAX;i++){
		if(isPrime[i]){
			for(j=2;i*j<MAX;j++){
				isPrime[i*j]=0;
			}
		}
	}
	while(scanf("%d %d",&N,&P),~P){
		solve();
	}
	return 0;
}