let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let acss = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d\n" @@ fun a b ->
      a,
      Array.fold_left ( lor ) 0 @@
      Array.init b @@ fun _ -> Scanf.scanf "%d " @@ fun c -> 1 lsl (c - 1) in
  let dp = Array.make (1 lsl n) 1145141919 in
  dp.(0) <- 0;
  for i = 0 to (1 lsl n) - 1 do
    Array.iter (fun (a, cs) ->
      dp.(i lor cs) <- min dp.(i lor cs) (a + dp.(i))) acss
  done;
  Printf.printf "%d\n" @@
  if dp.((1 lsl n) - 1) = 1145141919
  then -1
  else dp.((1 lsl n) - 1)

