#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int s;
    int sw[m][n];
    int rec[n]={0};
    rep(i,m){
        cin>>s;
        rep(j,s){
            cin>>sw[i][j];
            ++rec[sw[i][j]-1];
        }
    }
    int p[m],recp=0;
    rep(i,m){
        cin>>p[i];
        recp += p[i];
        if(recp == 2)recp = 0;
    }

    bool state=false;
    rep(i,n){
        if(rec[i] % 2 == recp && rec[i] != 0){
            state = true;
        }
    }
    int ans = 1;
    if(state == true){
        rep(i,n){
            if(rec[i] % 2 == recp)ans *= 2;
            else if(rec[i] == 0)ans *= 2;
            else;
        }
        cout<<ans/2;
    }
    else cout<<"0";
}