#include <bits/stdc++.h>
using namespace std;
using Int = long long;
signed main() {
  Int n, m;
  cin >> n >> m;
  vector<vector<Int>> k_s;
  vector<Int> p;
  for (Int i = 0; i < m; i++) {
    Int tmp_k;
    cin >> tmp_k;
    vector<Int> tmp_vs;
    tmp_vs.push_back(tmp_k);
    for (Int j = 0; j < tmp_k; j++) {
      Int tmp_s;
      cin >> tmp_s;
      tmp_vs.push_back(tmp_s);
    }
    k_s.push_back(tmp_vs);
  }
  for (Int i = 0; i < m; i++) {
    Int tmp_p;
    cin >> tmp_p;
    p.push_back(tmp_p);
  }
  Int ans = 0;
  for (Int i = 0; i < n * n; i++) {
    bitset<10> switches = static_cast<bitset<10>>(i);
    bool light_on = true;
    for (Int j = 0; j < m; j++) {
      Int tmp = 0;
      for (Int k = 1; k <= k_s[j][0]; k++) {
        if (switches[k_s[j][k] - 1]) tmp += 1;
      }
      if (tmp % 2 != p[j]) {
        light_on = false;
        break;
      }
    }
    if (light_on) ans += 1;
  }
  cout << ans << endl;
  return 0;
}
