module Main where

import qualified Data.ByteString.Char8         as BS
import           Data.List
import           Data.Char
import           Control.Monad
import           Data.Bits
import           Data.Function
import           Debug.Trace

main :: IO ()
main = do
  [n, m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  keys   <- replicateM m $ do
    [a, b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    cs     <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let bits = foldl' setBit zeroBits $ map pred cs
    return (a, bits)
  print $ solve n m keys

solve :: Int -> Int -> [(Int, Word)] -> Int
solve n m bs =
  -- traceShow bs
    minimumOrNone
    . map (sum . map fst)
    -- . traceShowId
    . filter (filled . map snd)
    $ subsequences bs
 where
  filled = (== 2 ^ n - 1) . foldl' (.|.) zeroBits
  minimumOrNone [] = -1
  minimumOrNone xs = minimum xs
