import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import qualified Data.IntMap.Strict as IM
import Data.Bits

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

parseBin :: Int -> [Int] -> Int
parseBin n xs = sum $ map (\x -> 2^(n-x)) xs

main :: IO ()
main = do
    [n,m] <- r'
    input <- replicateM m $ do
        [a, _]<- r'
        cs <- r'
        return (parseBin n cs, a)
    let inputMap = IM.fromListWith min input
    let ini = U.replicate (2^n) (-1 :: Int) U.// [(0,0)]
    let x = IM.foldlWithKey'
                 (\dp cs a ->
                    foldl' (\ndp cs' ->
                            let a'   = ndp U.! cs'
                                nIdx = cs .|. cs'
                                nVal = a' + a
                                oVal = ndp U.! nIdx
                            in  ndp U.// (if a' /= -1 && (nVal < oVal || oVal == -1)
                                    then [(nIdx, nVal)] else [])
                        )
                        dp [0..(2^n-1)]
                )
                ini inputMap
    print $ U.last x
