let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let kss =
    Array.init m @@ fun _ ->
      Scanf.scanf "%d " @@ fun k ->
        Array.init k @@ fun _ -> Scanf.scanf "%d " @@ fun s -> s in
  let ps = Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  Array.make n [true; false]
  |> Array.fold_left (fun candidates bs ->
      List.concat @@ List.map (fun b ->
        List.map (fun bs -> b :: bs) candidates) bs) [[]]
  |> List.filter (fun bs ->
      let bs' = Array.of_list bs in
      Array.fold_left ( && ) true @@
      Array.init m @@ fun i ->
        ( = ) (ps.(i) land 1) @@
        Array.fold_left (fun acc b ->
          acc lxor if bs'.(b - 1) then 1 else 0) 0 kss.(i))
  |> List.length
  |> Printf.printf "%d\n"