import Data.List (permutations) import Control.Applicative ((<$>)) import Data.Maybe (fromJust) import qualified Data.Vector.Unboxed as V import qualified Data.ByteString.Lazy.Char8 as B judge :: V.Vector Int -> V.Vector Int -> Int judge is t | V.elemIndex i1 is < V.elemIndex i2 is = s | otherwise = 0 where i1 = (V.!) t 0 i2 = (V.!) t 1 s = (V.!) t 2 main :: IO () main = do [n, _] <- map read . words <$> getLine ts <- map V.fromList . map (map (fst . fromJust . B.readInt)) . map B.words . B.lines <$> B.getContents print $ maximum $ map (\p -> sum $ map (judge p) ts) $ map V.fromList $ permutations [0 .. n - 1]