#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > s(m + 1);
  vector<int> p(m + 1);
  for (long long i = 1; i <= m; i++) {
    int k;
    cin >> k;
    s[i].resize(k);
    for (long long j = 1; j <= k; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  for (long long i = 1; i <= m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 1; i <= (1 << n); i++) {
    bool ok = true;
    for (int j = 1; j <= m; j++) {
      int c = 0;
      for (int id : s[j]) {
        if ((i >> id) & 1) {
          cout << id << " << " << i << " = " << (id << i) << " T" << endl;
          c++;
        } else {
          cout << id << " << " << i << " = " << (id << i) << " F" << endl;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    cout << endl;
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
