import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val scanner = new Scanner(in)
    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, m) =
        scanner.nextLine().split(" ").map(_.toInt)
      val point =
        Array
          .fill(n)(scanner.nextLine().split(" ").map(_.toLong))
          .map { case Array(x, y, z) =>
            x + y + z
          }
          .sortBy(_ * -1)
          .take(m)
          .sum
      output.println(point)
    }

  }

}
