// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System

let rec cartesian lst n = 
    match (lst, n) with
        | ([], _) -> []
        | (_,  0) -> []
        | (_,  1) -> [for x in lst -> [x]]
        | _       -> [for x in lst do for y in cartesian lst (n-1) -> [x]@y]


type Light(noIn:int, pIn:int, patternIn:int array) =
    let no = noIn
    let p = pIn
    let pattern = patternIn

    member this.IsOn(switches:bool list) = 
        //trueのみカウント
        //正確にはfun x -> x=trueだが面倒なのでidで代用
        let count = [for p in pattern -> switches.[p]] |> List.filter(id) |> List.length
        ((p+count) % 2 = 0)


[<EntryPoint>]
let main argv = 
    
    let inputs = stdin.ReadLine().Split(' ') |> Array.map int

    let numOfSwitches = inputs.[0]
    let numOfLights = inputs.[1]

    let switchPattern : int array array = Array.create numOfLights (Array.create 1 0)

    for i = 0 to numOfLights - 1 do
        switchPattern.[i] <- (stdin.ReadLine().Split(' ') |> Array.map (fun s -> int s - 1)).[1..]

    let ps = stdin.ReadLine().Split(' ') |> Array.map int

    //ライトの生成
    let lights = [for i in 0..(numOfLights-1) -> new Light(i, ps.[i], switchPattern.[i])]

    //パターンを総当たりで数える
    let count = cartesian [false; true] numOfSwitches 
                |> List.filter(fun x -> lights |> List.forall(fun y -> y.IsOn x))
                |> List.length
            
    printfn "%d" count

    0 // return an integer exit code
