fun main(args:Array<String>?): Unit {
    val primes = primesUnder(102_000)
    while(true){
        val (n, p) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == -1) return
        val upper = upperBound(primes, n)
        val nextPair = IntArray(p){it}
        repeat(p - 1){
            (nextPair.indices).minBy{primes[it + upper] + primes[nextPair[it] + upper]}!!.let{
                nextPair[it]++
            }
        }
        println(nextPair.indices.map { primes[it + upper] + primes[nextPair[it] + upper] }.min())
    }
}
fun primesUnder(upperLimit: Int): IntArray {
    val isPrime = BooleanArray(upperLimit + 1){true}
    for (p in 2 .. Math.sqrt(upperLimit.toDouble()).toInt()) if (isPrime[p]){
        for (j in p * p .. upperLimit step p){
            isPrime[j] = false
        }
    }
    return (2 .. upperLimit).filter(isPrime::get).toIntArray()
}
fun upperBound(array: IntArray, target: Int): Int {
    var left = 0
    var right = array.size
    while(left < right){
        val mid = (left + right) / 2
        if (array[mid] <= target) left = mid + 1
        else right = mid
    }
    return right
}
