#include <stdio.h>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;

int n, m, mask[10], p[10], pm, cnt = 0;
void rec(int bits, int d) {
	if (d < 0) {
		cnt += bits == pm;
		return;
	}
	rec(bits, d - 1);
	rec(bits ^ mask[d], d - 1);
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int k, s;
		scanf("%d", &k);
		for (int j = 0; j < k; j++) {
			scanf("%d", &s);
			mask[s - 1] ^= (1 << i);
		}
	}
	for (int i = 0; i < m; i++) {
		scanf("%d", p + i);
		pm ^= p[i] << i;
	}
	rec(0, n - 1);
	printf("%d\n", cnt);
}