{-# 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 . head $ power m a (n - 1) power :: Int -> [[Int]] -> Int -> [[Int]] power n a b | b == 0 = [[0 | _ <- [1..n]] | _ <- [1..n]] | 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 = let b' = transpose b in [[maximum $ zipWith (+) x y | y <- b'] | x <- a]