object Main {
    def combinations2(s: Stream[Int]) = for (i <- s.indices; j <- i to s.indices.last) yield (s(i), s(j))
            
    def isPrime(n: Int) = n > 1 && (2 to math.sqrt(n).toInt).forall(n % _ != 0)

    def m(n: Int, p: Int): Int = {
        val s = combinations2(Stream.from(n+1).filter(isPrime).take(p)).map(x => x._1 + x._2).sorted
        s(p - 1)
    }

    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
        for (x <- in if !x.contains(-1)) println(m(x(0), x(1)))
    }
}