#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int a, b;
  int p[19];
  vector<int> sw[19];
  cin >> a >> b;
  for (int i = 0; i < b; i++) {
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int z;
      cin >> z;
      sw[i].push_back(z);
    }
  }
  for (int i = 0; i < b; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 0; i <= a; i++) {
    int vet[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    for (int j = 0; j < i; j++) {
      vet[j] = 0;
    }
    bool first = true;
    while (first || next_permutation(vet, vet + a)) {
      bool cond = true;
      for (int t = 0; t < b; t++) {
        int cont = 0;
        for (auto e : sw[t]) {
          if (vet[e - 1] == 1) cont++;
        }
        if (cont % 2 != p[t]) cond = false;
      }
      if (cond) ans++;
      first = false;
    }
  }
  cout << ans << endl;
  return 0;
}
