var
	r1,r2,ans,id,N,M,i,j,k,s:Longint;
	A:array[1..10,1..10]of Boolean;
	B:array[1..10,1..11]of Boolean;
	tmp:Boolean;
begin
	read(N,M);
	for i:=1 to M do begin
		read(k);
		for j:=1 to k do begin
			read(s);
			A[i,s]:=True;
			B[i,s]:=True;
		end;
	end;
	for i:=1 to M do begin
		read(s);
		if s=1 then B[i,N+1]:=True;
	end;
	for i:=1 to M do begin
		if i>N then break;
		id:=i;
		while(id<=M)and(not A[id,i])do inc(id);
		if id>N then continue;
		for j:=i to N do begin
			tmp:=A[id,j];
			A[id,j]:=A[i,j];
			A[i,j]:=tmp;
		end;
		inc(r1);
		for j:=i+1 to M do begin
			if A[j,i]then begin
				for k:=i to N do begin
					A[j,k]:=A[j,k]xor A[i,k];
				end;
			end;
		end;
	end;
	for i:=1 to M do begin
		if i>N+1 then break;
		id:=i;
		while(id<=M)and(not B[id,i])do inc(id);
		if id>N+1 then continue;
		for j:=i to N+1 do begin
			tmp:=B[id,j];
			B[id,j]:=B[i,j];
			B[i,j]:=tmp;
		end;
		inc(r2);
		for j:=i+1 to M do begin
			if B[j,i]then begin
				for k:=i to N+1 do begin
					B[j,k]:=B[j,k]xor B[i,k];
				end;
			end;
		end;
	end;
	ans:=1;
	if r1<>r2 then ans:=0;
	for i:=1 to N-r1 do ans:=ans*2;
	writeln(ans);
end.
