#include <bits/stdc++.h>
using namespace std;
bool setcontain(set<int> const& X, int const x) {
  std::set<int>::iterator itr = X.begin();
  for (int i = 0; i < X.size(); i++) {
    if ((*itr) == x) {
      return 1;
    }
    itr++;
  }
  return 0;
}
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<set<int> > ks(M);
  vector<int> p(M);
  int tmp = 0, in, ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    for (int j = 0; j < tmp; j++) {
      cin >> in;
      ks.at(i).insert(in);
    }
  }
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> p[i];
  }
  int count;
  bool frag = true;
  for (int bit = 0; bit < (1 << N); bit++) {
    frag = true;
    for (int i = 0; i < M; i++) {
      count = 0;
      for (int bits = 0; bits < N; bits++) {
        if (bit & (1 << bits)) {
          if (setcontain(ks.at(i), bits + 1)) {
            count++;
          }
        }
      }
      if (count % 2 == p[i]) {
        frag = false;
      }
    }
    if (frag) {
      ans++;
      cout << bit << endl;
      ;
    }
  }
  cout << ans << endl;
  ;
  return 0;
}
