#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = -100100100;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m, vector<int>(n));
  vector<int> ks(m);
  for (int i = 0; i < (m); ++i) {
    int k;
    cin >> k;
    ks[i] = k;
    for (int j = 0; j < (k); ++j) cin >> s[i][j];
  }
  vector<int> p(m);
  for (int i = 0; i < (m); ++i) cin >> p[i];
  int rel = 0;
  for (int i = 1; i < (n + 1); ++i) {
    vector<int> a(n, 4);
    for (int k = 0; k < (i); ++k) a[k] = 1;
    do {
      bool ans = true;
      for (int j = 0; j < (m); ++j) {
        int chk = 0;
        for (int l = 0; l < (ks[j]); ++l) {
          if (a[s[j][l] - 1] == 1) ++chk;
        }
        if (chk % 2 != p[j]) ans = false;
      }
      if (ans) rel++;
    } while (next_permutation(a.begin(), a.end()));
  }
  cout << rel << endl;
  return 0;
}
