N=io.read("n")
M=io.read("n")
x,y,z,t={},{},{},{}
for i=1,N do
  x[i]=io.read("n")
  y[i]=io.read("n")
  z[i]=io.read("n")
  t[i]=math.abs(x[i])+math.abs(y[i])+math.abs(z[i])
end
table.sort(t,function (a,b) return a>b end)
max=0
for i=1,M do
  max=max+t[i]
end
print(max)



  