import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    xyz <- replicateM n getIntList
    let pms = sequence $ replicate 3 [1,-1]
    let f pm = sum . take m . sortOn Down $ map (sum . zipWith (*) pm) xyz
    let ans = maximum $ map f pms
    print ans