import std.stdio, std.conv, std.algorithm, std.string;

enum max = 100101;

const list = makeTable();

int[] makeTable(){
    bool[] table = new bool[](max);
    int[] list;
    table[] = true;
    table[0..2] = false;
    for(int i = 4; i < max; i += 2){
        table[i] = false;
    }
    for(int i = 3; i * i < max; i += 2){
        for(int j = i + i; j < max; j += i){
            table[j] = false;
        }
    }
    foreach(i; 0..max){
        if(table[i]) list ~= i;
    }
    return list;
}

void main(){
    while(true){
        auto input = readln.split.map!(to!int);
        if(input[0] == -1 && input[1] == -1) break;
        M(input[0], input[1]).writeln;
    }
}

int M(int N, int P){
    int[int] memo;
    size_t start;
    foreach(i, p; list){
        if(N < p){
            start = i;
            break;
        }
    }

    foreach(i; start..start + P){
        foreach(j; start..start + P){
            if(i > j){
                swap(i, j);
            }
            memo[(list[i] << 17) + list[j]] = list[i] + list[j];
        }
    }

    return memo.values.sort!("a < b", SwapStrategy.stable)()[P];
}