Scanf.scanf "%d %d" (fun n m ->
    let lim = 1 lsl n in
    let sentinel = max_int / 2 in
    let dp = Array.make lim sentinel in
    dp.(0) <- 0;
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun x y ->
            let rec loop i acc =
                if i = y then acc else
                    let c = Scanf.scanf " %d" (fun c -> c) in
                    loop (i + 1) (acc lor (1 lsl (c - 1)))
            in
            let c = loop 0 0 in
            for j = 0 to lim - 1 do
                dp.(j lor c) <- min dp.(j lor c) (dp.(j) + x)
            done
        )
    done;
    Printf.printf "%d\n" @@ if dp.(lim - 1) = sentinel then -1 else dp.(lim - 1)
)