#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, k, l, s, ppp, cou;
  ppp = 0;
  cin >> n >> m;
  vector<int> vec(n);
  vector<vector<int>> date(m + 1, vector<int>(n + 1));
  for (i = 0; i < m; i++) {
    cin >> k;
    for (l = 0; l < k; l++) {
      cin >> s;
      date.at(i).at(s) = 1;
    }
  }
  vector<int> kazu(m);
  for (int ll = 0; ll < m; ll++) {
    cin >> kazu.at(ll);
  }
  while (true) {
    for (int ii = 0; ii < m; i++) {
      cou = 0;
      for (int iii = 0; iii < n; iii++) {
        if (date.at(m).at(iii) == vec.at(iii)) {
          cou = cou + 1;
        }
      }
      if (cou % 2 == kazu.at(ii)) {
        if (ii == m - 1) {
          ppp = ppp + 1;
          break;
        }
      } else {
        break;
      }
    }
    vec.at(0) = vec.at(0) + 1;
    for (i = 0; i < n - 1; i++) {
      if (vec.at(i) == 2) {
        vec.at(i) = 0;
        vec.at(i + 1) = vec.at(i + 1) + 1;
      }
    }
    if (vec.at(n) == 2) {
      break;
    }
  }
  cout << ppp;
}
