import Control.Monad
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.map(unfoldr(B.readInt.B.dropWhile isSpace)).B.lines=<<B.getContents
solve([n,m]:xyzs)=maximum.map(f.(\v->map(sum.zipWith(*)v)xyzs))$replicateM 3[-1,1]where
  f=(V.!m).foldr g(V.replicate(m+1)$minBound`div`2)
  g t dp=V.generate(m+1)$ \i->max(dp V.! i)$if i>0 then t+dp V.!(i-1) else 0