#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];

    let mut a : Vec<Vec<i32>> = Vec::with_capacity(m);
    for _i in 0..m {
        let mut row:Vec<i32> = vec![0;n];

        let kss = read_vec::<usize>();
        let k = kss[0];
        for j in 1..k+1 {
            let s = kss[j];
            row[s-1] = 1;
        }
        a.push(row);
    }

    let ps = read_vec::<i32>();
    for i in 0..m {
        a[i].push(ps[i]);
    }

    // println!("a: {:?}", a);


    let num = solve(m, n, &mut a);

    println!("{}", num);

}

fn solve(m :usize, n: usize, a: &mut [Vec<i32>]) -> usize {
    let rank = gauss_jordan_mod2(m, n, a);

    if rank < m {
        for i in rank..m {
            if a[i][n] != 0 {
                return 0;
            }
        }
    }

    let mut num = 1;
    for _i in rank..n {
        num *= 2;
    }
    return num;
}


// Get rank for m rows n+1 columns augmented matrix
fn gauss_jordan_mod2(m :usize, n: usize, a: &mut [Vec<i32>]) -> usize {
    let mut rank : usize = 0;

    for j in 0..n {
        let mut pivot : usize = m;
        // 1. Get pivot
        for i in rank..m {
            if a[i][j] != 0 {
                pivot = i;
                break;
            }
        }

        if pivot == m {
            continue;
        }

        // 2. Swap
        a.swap(rank, pivot);

        // 3. Set a[i][j] (i != rank) to zero
        for i in 0..m {
            if i == rank {
                continue;
            }
            if a[i][j] == 0 {
                continue;
            }
            for j1 in 0..n+1 {
                a[i][j1] -= a[rank][j1];
                if a[i][j] < 0 {
                    a[i][j] += 2;
                }
            }
        }

        rank += 1;
    }

    return rank;
}
