#include <bits/stdc++.h>
using namespace std;
int DEPTH;
int ans = 0;
int N, M;
int k[100], s[100][100], p[100];
vector<int> Num;
void calc(vector<int> v) {
  priority_queue<int, vector<int>> asc;
  vector<int> tmp(10, 0);
  bool flag = true;
  for (int i = 0; i < 10; i++) {
    if (v[i] == 1) asc.push(Num[i]);
  }
  while (!asc.empty()) {
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < k[i]; j++) {
        if (s[i][j] == asc.top()) {
          tmp[i] += 1;
        }
      }
    }
    asc.pop();
  }
  for (int i = 0; i < M; i++) {
    if (tmp[i] % 2 != p[i]) flag = false;
  }
  if (flag) {
    ans++;
  }
}
void DFS(int depth, vector<int> v) {
  if (depth == DEPTH) {
    calc(v);
    return;
  }
  for (int i = 0; i < 2; i++) {
    v[depth] = i;
    DFS(depth + 1, v);
  }
}
int main() {
  vector<int> v(10, 0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) cin >> s[i][j];
  }
  for (int l = 1; l <= 10; l++) {
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < k[i]; j++) {
        if (s[i][j] == l) {
          Num.push_back(l);
          break;
        }
      }
      if (Num[Num.size() - 1] == l) break;
    }
  }
  DEPTH = Num.size();
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  DFS(0, v);
  cout << ans * pow(2, N - Num.size()) << endl;
}
