#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int>> swithes;
vector<int> p;
int main() {
  cin >> N >> M;
  swithes.resize(M);
  p.resize(M);
  for (int i = 0; i < (int)(M); ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < (int)(k); ++j) {
      int l;
      cin >> l;
      --l;
      swithes[i].push_back(l);
    }
  }
  for (int i = 0; i < (int)(M); ++i) cin >> p[i];
  int ans = 0;
  for (int bit = 0; bit < (1 << N); ++bit) {
    bool flag = true;
    for (int i = 0; i < (int)(M); ++i) {
      int res = 0;
      for (int j = 0; j < swithes[i].size(); ++j) {
        if (bit & (1 << swithes[i][j])) res++;
      }
      if (res % 2 == p[i])
        continue;
      else {
        flag = false;
        break;
      }
    }
    if (flag) ans++;
    cout << ans << " ";
  }
  cout << ans << endl;
}
