use std::io::Read;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        let y = max!($($z),*);
        if $x > y {
            $x
        } else {
            y
        }
    }}
}
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        let y = min!($($z),*);
        if $x < y {
            $x
        } else {
            y
        }
    }}
}

use std::io::stdin;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[derive(Debug)]
pub struct Test {

}

impl Test {
    pub fn new(param: ()) -> Test {
        Test {
        }
    }

    fn solve(&mut self) -> usize {
        0
    }
}
fn main() {
    let n: usize = read();
    let m: usize = read();

    let mut s: Vec<Vec<usize>> = Vec::new();
    for _ in 0..m {
        let k: usize = read();
        let mut p: Vec<usize> = Vec::new();
        for _ in 0..k {
            p.push(read());
        }
        s.push(p);
    }

    let mut p: Vec<usize> = Vec::new();
    for _ in 0..m {
        p.push(read());
    }


    let mut count = 0;
    for i in 0..2usize.pow(n as u32) {
        let mut on_flag = false;
        for (sv, p) in s.iter().zip(p.iter()) {
            let on_count = sv.iter().fold(0, |acc, a| {
                acc + if i & (1 << (a-1)) > 0 { 1 } else { 0 }
            });

            if on_count % 2 == *p {
                on_flag = true;
            } else {
                on_flag = false;
                break;
            }
        }
        
        if on_flag { count += 1; }
    }

    println!("{}", count);
}


Measured memory_bytes: 4352