#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<int> sw(10);
int x(int bit) {
	int result = 0;
	for (int i = 0; bit > 0; bit >>= 1, i++) {
		if (bit & 1)
			result ^= sw[i];
	}
	return result;
}

int main() {
	cin >> n >> m;
	for (int k, bit = 1 << (m - 1), s; bit > 0; bit >>= 1) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			s--;
			sw[s] |= bit;
		}
	}

	int p = 0;
	for (int i = 0, q; i < m; i++) {
		cin >> q;
		p <<= 1;
		p += q;
	}

	int result = 0;
	for (int bit = 0; bit < 1 << n; bit++) {
		if (x(bit) == p)
			result++;
	}
	cout << result << endl;
}
