import Control.Monad (replicateM) import Data.List (permutations) getPoint l (x:y:zs) | filter (\a -> x==a||y==a) l == [x,y] = head zs | otherwise = 0 main = do n:m:_ <- map read <$> words <$> getLine pointList <- replicateM m (map read <$> words <$> getLine) let lines = permutations [0..(n-1)] results = map sum $ zipWith map (zipWith id (repeat getPoint) lines) $ repeat pointList print $ foldr max 0 results