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

#define N   100000
#define P      100
#define PN  200000
#define INT(X) \
  ( *( (const int *)(X) ) )

static int d[ P * P ];
static int p[ PN ] = { 1, 1 };
static int pn = 0;

int
compare (
  const void *a,
  const void *b
  )
{
  return ( INT( a ) - INT( b ) );
}

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;

  for ( i = 2; i * i < PN; ++i )
  {
    if ( p[ i ] ) continue ;
    for ( j = i * i; j < PN; j += i )
      p[ j ] = 1;
  }
  for ( i = 2; i < PN; ++i )
  {
    if ( p[ i ] ) continue ;
    p[ pn++ ] = i;
  }

  for ( ; ; )
  {
    int l, c, s;
    int lp = 0;

    scanf ( "%d%d", &l, &c );
    if ( l == -1 && c == -1 ) break ;

    while ( p[ lp ] <= l )
      ++lp;

    s = 0;
    for ( i = lp; i < lp + P; ++i )
    for ( j = i; j < lp + P; ++j )
    {
      d[ s++ ] = p[ i ] + p[ j ];
    }
    qsort ( d, s, sizeof ( int ), compare );
    printf ( "%d\n", d[ c - 1 ] );
  }

  return ( EXIT_SUCCESS );
}