import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val x = new Array[Long](N+1)
  val y = new Array[Long](N+1)
  val z = new Array[Long](N+1)

  for(i <- 1 to N) {
    val a, b, c = in.next().toLong
    x(i) = a
    y(i) = b
    z(i) = c
  }
  // println(x.deep, y.deep, z.deep)


  //
  var ans = 0L
  val hoge = Seq(-1, 1)
  for(xvol <- hoge; yvol <- hoge; zvol <- hoge) {
    val tmp = (1 to N).map { i =>
      x(i) * xvol + y(i) * yvol + z(i) + zvol
    }

    val tmp2 = tmp.sorted.reverse.slice(0, M).sum

    //println(tmp)
    ans = Math.max(ans, tmp2)
  }

  println(ans - M)

}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

