object Main {
    def matsuzakiNums(s: Stream[Int]) = {
        (for {
            n <- s.zipWithIndex if n._2 <= math.sqrt(s.size)
            m <- s.dropWhile(_ < n._1)
        } yield n._1 + m).sorted
    }
            
    def isPrime(n: Int) = n > 1 && (2 to math.sqrt(n).toInt).forall(n % _ != 0)

    def m(n: Int, p: Int): Int = matsuzakiNums(Stream.from(n + 1).filter(isPrime).take(p))(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)))
    }
}