#include <iostream>
#include <assert.h>
#include <vector>
#include <map>
#include <algorithm>
//#include <functional>

class light_status{
    public:
        light_status(int32_t id, int32_t nswitch, bool target)
            :light_id(id), num_switches(nswitch), target_cond(target), on_cnt(0), checked_cnt(0)
        {
        }
        light_status(int32_t id, int32_t nswitch)
            :light_id(id), num_switches(nswitch), target_cond(true), on_cnt(0), checked_cnt(0)
        {
            //std::cout << "constructor with nswitch called" << std::endl;
        }
        //light_status(const light_status &obj)
        //    : num_switches(obj.num_switches), target_cond(obj.target_cond),
        //      on_cnt(0), checked_cnt(0)
        //{
        //    //light_status(obj.num_switches, obj.target_cond);
        //}
        ~light_status(){}

        void set_target_status(bool odd){
            target_cond = odd;
            return;
        }
        
        bool switch_change(bool on){
            if(on){
                on_cnt++;
            }
            checked_cnt++;

            //debug
            //std::cout << "light ID:" << light_id << "  changed to: " << on << ". check_cnt,on_cnt = : " << checked_cnt << "," << on_cnt << std::endl;

            if(num_switches == checked_cnt){
                if(on_cnt % 2 == (int32_t) target_cond){
                    return true;
                }
                else{
                    return false;
                }
            }
            return true;
        }
        void cancel_switch(bool on){
            if(on){
                on_cnt--;
            }
            checked_cnt--;
            
            //debug
            //std::cout << "light ID:" << light_id << "  canceled from: " << on << ". check_cnt,on_cnt = : " << checked_cnt << "," << on_cnt << std::endl;

            return;
        }
        
        void dbg_dump(){
                std::cout << "light status dump[id,num_switch,target_cond,on_cnt,_checkedcnt] = ["
                << light_id << "," << num_switches << "," << target_cond << "," << on_cnt << "," << checked_cnt << "]" << std::endl;
        }

    private:
        int32_t light_id;
        int32_t num_switches;
        bool target_cond; //odd:True
        int32_t on_cnt;
        int32_t checked_cnt;
};

void dfs(
    std::vector<std::vector<int32_t>>& switch_vec,
    std::vector<light_status>& lights_vec,
    int32_t switch_id, int32_t& result){

    //debug
    //std::cout << "swith_id: " << switch_id << " process" << std::endl;

    if(switch_id == (int32_t)switch_vec.size()){
        result++;
        return;
    }

    std::vector<int32_t>& light_ids = switch_vec[switch_id];
    int32_t proc_cnt = 0;
    bool next_step = true;
    //switch_on
    for(auto& light_id : light_ids){
        proc_cnt++;
        next_step = lights_vec[light_id].switch_change(true);
        if(!next_step){
            break;
        }
    }
    //debug
    //std::cout << "on cnt: " << proc_cnt << std::endl;

    if(next_step){
        dfs(switch_vec, lights_vec, switch_id+1, result);
    }
    //cancel ops
    for(int32_t i = 0; i < proc_cnt; i++){
        lights_vec[light_ids[i]].cancel_switch(true);
    }

    proc_cnt = 0;
    next_step = true;
    //switch_off
    for(auto& light_id : light_ids){
        proc_cnt++;
        next_step = lights_vec[light_id].switch_change(false);
        if(!next_step){
            break;
        }
    }
    
    //debug
    //std::cout << "off cnt: " << proc_cnt << std::endl;
    
    if(next_step){
        dfs(switch_vec, lights_vec, switch_id+1, result);
    }
    //cancel ops
    for(int32_t i = 0; i < proc_cnt; i++){
        lights_vec[light_ids[i]].cancel_switch(false);
    }

    return;
}

int main(){
    int32_t N, M;
    std::cin >> N >> M;

    //naiive: 2^N x M ... feasible?
    //from S0 to Sn
    //  check M condition.
    //      if cond == NG brea;
    //      if all M cond == OK cnt++;

    std::vector<std::vector<int32_t>> switch_vec(N);
    std::vector<light_status> lights_vec;
    for(int32_t i = 0; i < M; i++){
        int32_t num_switches = 0;
        std::cin >> num_switches;
        for(int32_t j = 0; j < num_switches; j++){
            int32_t switch_id = 0;
            std::cin >> switch_id;
            switch_vec[switch_id-1].push_back(i);
        }
        lights_vec.push_back(light_status(i, num_switches));
    }

    for(int32_t i = 0; i < M; i++){
        bool odd;
        std::cin >> odd;
        lights_vec[i].set_target_status(odd);
    }

    //debug
    //lights_vec[0].dbg_dump();
    //lights_vec[1].dbg_dump();

    int32_t result = 0;
    dfs(switch_vec, lights_vec, 0, result);
    std::cout << result;


    return 0;
}


Measured memory_bytes: 256