import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
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
    vec <- VM.replicate (2^n) (-1 :: Int)
    VM.write vec 0 0 
    x <- forM_ (IM.toList inputMap)
                (\(cs,a) ->
                    forM_ [0..(2^n-1)] (\cs' -> do
                            a' <- VM.read vec cs'
                            let nIdx = cs .|. cs'
                                nVal = a' + a
                            oVal <- VM.read vec nIdx
                            if a' /= -1 && (nVal < oVal || oVal == -1)
                                    then VM.write vec nIdx nVal
                                    else return ()
                        )
                )
    res <- VM.read vec (2^n-1)
    print res
