{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Bits             (testBit)
import qualified Data.ByteString.Char8 as BC
import           Data.List             (sortOn)
import           Data.Maybe            (fromJust)
import           Data.Ord              (Down (Down))

main :: IO ()
main = do
  [n, m] <- readInts <$> BC.getLine
  xyzs <- map readInts . BC.lines <$> BC.getContents
  print $ solve n m xyzs

solve :: Int -> Int -> [[Int]] -> Int
solve n m xyzs = maximum $ map solve1 [(0 :: Int) .. 7] where
  solve1 i = sum . take m $ sortOn Down scores where
    scores = map (sum . zipWith (*) (coef i)) xyzs

coef :: Int -> [Int]
coef i = map test [0 .. 2] where
  test k = if testBit i k then 1 else -1

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt

readInts :: BC.ByteString -> [Int]
readInts = map readInt . BC.words
