#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  vector<vector<int>> d(m);
  vector<int> val(m);
  vector<int> digit(n, 0);
  vector<int> hantei(n, 1);
  for (int i = 0; i < m; i++) {
    int cnt;
    cin >> cnt;
    d[i] = vector<int>(cnt);
    for (int j = 0; j < cnt; j++) cin >> d[i][j];
  }
  for (int i = 0; i < m; i++) cin >> val[i];
  while (1) {
    digit[0] += 1;
    for (int i = 0; i < n; i++) {
      if (digit[i] == 2) {
        digit[i + 1] += 1;
        digit[i] = 0;
      }
    }
    bool flag = true;
    for (int i = 0; i < m; i++) {
      int num = 0;
      for (int j = 0; j < d[i].size(); j++) {
        if (digit[d[i][j] - 1] == 1) num++;
      }
      if (num % 2 != val[i]) flag = false;
    }
    if (flag) cnt++;
    flag = true;
    if (hantei == digit) break;
  }
  cout << cnt << endl;
  return 0;
}
