#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n: u32 = read();
    let m: usize = read();

    let mut vvs = Vec::new();
    for _ in 0..m {
        let vs: Vec<u32> = {
                let s = {
                    let mut s = String::new();
                    std::io::stdin().read_line(&mut s).unwrap();
                    s.trim_right().to_owned()
                };
                let mut ws = s.split_whitespace();
                let mut vs = Vec::new();
                let k = ws.next().unwrap().parse().unwrap();
                for _ in 0..k {
                    vs.push(ws.next().unwrap().parse().unwrap());
                }
                vs
        };
        vvs.push(vs);
    }
    let ps: Vec<u32> = {
        let s = {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_owned()
        };
        let mut ws = s.split_whitespace();
        let mut vs = Vec::new();
        for _ in 0..m {
            vs.push(ws.next().unwrap().parse().unwrap());
        }
        vs
    };
    let v = (1..n+1).map(|c| c).collect::<Vec<_>>();

    // 1 << d := pow(2, d)
    let mut scnt  = 0;
    for i in 0..1 << v.len() {
        let mut nn = Vec::new();
        for j in 0..v.len() {
            // iのj番目ビットが立っているか -> jがiに含まれるか
            if 1 << j & i == 0 {
                nn.push(v[j]);
            }
        }
        let mut flag = true;
        for (q, k) in vvs.iter().enumerate() {
            let mut cnt = 0;
            for l in k.iter() {
                for r in nn.iter() {
                    if l == r {
                        cnt+=1;
                    }
                }
            }
            if ps[q] != cnt % 2 {
                flag = false;
                break;
            }
        }
        if flag {
            scnt+=1;
        }
    }
    print!("{}", scnt);
}

Measured memory_bytes: 4352