{-# LANGUAGE ScopedTypeVariables #-} import Control.Monad import Control.Applicative import Data.List main :: IO () main = do (n :: Int) <- readLn (m :: Int) <- readLn a <- map (map read . words) <$> replicateM m getLine print . maximum . concat $ power m a (n - 1) power :: Int -> [[Int]] -> Int -> [[Int]] power n a b | b == 1 = a | even b = power n (multiply a a) (b `div` 2) | otherwise = multiply a $ power n a (b - 1) multiply :: [[Int]] -> [[Int]] -> [[Int]] multiply a b = [[maximum $ zipWith (+) x y | y <- transpose b] | x <- a]