{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.IntMap as M

readIntLL :: IO [[Int]]
readIntLL = map(unfoldr(B.readInt.B.dropWhile(==' '))).B.lines<$>B.getContents

rsort :: Ord a => [a] -> [a]
rsort = sortBy$flip compare

f :: [Int] -> [Int]
f = (flip map)[[s,g,h]|s<-[1,(-1)],g<-[1,(-1)],h<-[1,(-1)]].(sum.).zipWith(*)

main=do
    [n,m]:xyzs <- readIntLL
    print
        $ head $ rsort $ map (sum . take m . rsort)
        $ transpose $ map f $ take n xyzs
