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

char prime_list_beta[200000];
int prime_list[200000];
int prime_num;

void make_prime_list(void) {
	int i,j;
	for(i=2;i<200000;i++)prime_list_beta[i]=1;
	for(i=2;i*i<200000;i++) {
		if(prime_list_beta[i]) {
			for(j=i+i;j<=200000;j+=i)prime_list_beta[j]=0;
		}
	}
	prime_num=0;
	for(i=2;i<200000;i++) {
		if(prime_list_beta[i])prime_list[prime_num++]=i;
	}
}

int find_min_prime(int n) {
	int left,right,mid;
	left=0;right=prime_num-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(n<prime_list[mid])right=mid-1; else left=mid+1;
	}
	return right+1;
}

int qsort_comp(const void* x,const void* y) {
	const int* a=(const int*)x;
	const int* b=(const int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int thelist[10000];

int main(void) {
	int N,P;
	make_prime_list();
	while(scanf("%d%d",&N,&P)==2 && (N!=-1 || P!=-1)) {
		int start=find_min_prime(N);
		int i,j,pos;
		if(prime_num-start<100)return 1;
		pos=0;
		for(i=0;i<P;i++) {
			for(j=i;j<P;j++)thelist[pos++]=prime_list[start+i]+prime_list[start+j];
		}
		qsort(thelist,pos,sizeof(int),qsort_comp);
		printf("%d\n",thelist[P-1]);
	}
	return 0;
}