let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let arr = Array.init m (fun _ -> List.tl (split (read_line ()))) in
        let p = Array.of_list (split (read_line ())) in
        let sw = Array.make m 0 in
        for i = 0 to m - 1 do
            sw.(i) <- List.fold_left (fun acc v -> acc lor (1 lsl (v - 1))) 0 arr.(i)
        done;
        let count bits =
            let rec loop i acc =
                if i = 0 then acc else loop (i / 2) (acc + i land 1)
            in
            loop bits 0
        in
        let forall bits switch p =
            let rec loop i =
                if i < 0 then true else
                if count (switch.(i) land bits) mod 2 = p.(i) then loop (i - 1) else false
            in
            loop (m - 1)
        in
        let rec loop i acc =
            if i < 0 then acc else
                let acc = if forall i sw p then acc + 1 else acc in
                loop (i - 1) acc
        in
        let ans = loop ((1 lsl n) - 1) 0 in
        Printf.printf "%d\n" ans
    in
    main ()