#include<stdio.h>
#define M 200000
int main(){
  int i,j,t,r,s[10000],a,b,c,d;
  char p[M]={1,1};
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  while(scanf("%d %d",&a,&b),a+1||b+1){
    r=c=0;
    for(i=a+1;c++<b;i++){//printf(" %d\n",c);
      while(p[i])i++;
      d=c-1;
      for(j=i;d++<b;j++){
	while(p[j])j++;
	s[r++]=i+j;//printf("%d\n",s[r-1]);
      }
    }
    for(i=0;i<b;i++){
      for(j=r-1;j>i;j--){
	if(s[j-1]>s[j]){
	  t=s[j-1];
	  s[j-1]=s[j];
	  s[j]=t;
	}
      }
    }
    printf("%d\n",s[b-1]);
  }
  return 0;
}