// C - Switches
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N,M; cin>>N>>M;

	vi S(M);
	for(int m=0; m<M; ++m){
		int k; cin>>k;
		while(k--){ int s; cin>>s; S[m] |= 1<<(s-1); }
	}

	vi P(M); for(int p=0; p<M; ++p) cin>>P[p];

	int all = 1<<N, unmatch_count = 0;
	for(int s=0; s<all; ++s){//s: sw all pattern
		int b,m;
		for(m=0; m<M; ++m){//S[m]: sw data matching
			int sw = s & S[m];
			b = 0; while(sw){ if(sw&1) b=++b%2; sw/=2; }//count bit '1'
			if(b!=P[m]) break;
		}
		if(m<M && b!=P[m]) ++unmatch_count;
	}
	cout<< all - unmatch_count <<endl;
}