macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
}

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)*}
    };
}

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<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $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")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}



fn main() {


  input! { 
         n: i32, 
         m: i32,
         switch: [[i32]; m],
         state: [i32; m]
    }

    let mut zenken2 :Vec<Vec<i32>> = Vec::new();
    fn rec(pos :i32, s : &mut Vec<i32>,n:i32,zenken:&mut Vec<Vec<i32>>){
        if pos >= n as i32 {
            zenken.push(s.to_vec());
            return;
        }
        for i in 0..2 {
            s.push(i);
            let pos2 = pos + 1;
            rec(pos2, s, n, zenken);
            s.pop();
        }
    }
    
    rec(0,&mut Vec::new(),n,&mut zenken2);
    //mydbg!(zenken2.len());
    
    let mut result = 0;
    'start : for item in zenken2{
        for (index,p) in state.iter().enumerate(){
            let sw = &switch[index as usize];
            let mut sum = 0;
            for i in 0..sw.len(){
                let switch_no = sw[i]-1;
                sum += item[switch_no as usize];
            }  
            if sum % 2 != *p{
                continue 'start;
            }
        }
        //mydbg!(result);
        result += 1;
    }

   
   
   println!("{}",result);


}
	　