N=io.read("n")
M=io.read("n")
x,y,z,t={},{},{},{}
for i=1,N do
  x[i]=io.read("n")
  if x[i]<0 then
    x[i]=-x[i]
  end
  y[i]=io.read("n")
  if y[i]<0 then
    y[i]=-y[i]
  end
  z[i]=io.read("n")
  if z[i]<0 then
    z[i]=-z[i]
  end
  t[i]=x[i]+y[i]+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)



  