#include <bits/stdc++.h>
using namespace std;
int N, M, a[10] = {0}, p[10] = {0};
int S[10][10] = {0};
int dfs(int i, int sum);
int ddd = 0;
int main() {
  cin >> N >> M;
  int k;
  int i, t = 0;
  int n;
  for (i = 0; i < M; i++) {
    cin >> k;
    for (t = 0; t < k; t++) {
      cin >> n;
      S[i][n - 1] = 1;
    }
  }
  for (i = 0; i < M; i++) {
    cin >> p[i];
  }
  for (i = 0; i < M; i++) {
    cout << p[i] << " ";
  }
  int count = 0;
  count = dfs(0, 0);
  cout << count;
  return 0;
}
int dfs(int i, int sum) {
  int t;
  bool check = true;
  int lsum, rsum;
  int v;
  int score[10] = {0};
  if (i == N) {
    for (v = 0; v < M; v++) {
      for (t = 0; t < N; t++) {
        if (S[v][t] == 1 && a[t] == 1) {
          score[v]++;
        }
      }
    }
    for (t = 0; t < M; t++) {
      if (score[t] % 2 != p[t]) {
        check = false;
      }
    }
    if (check == true)
      return 1;
    else
      return 0;
  }
  a[i] = 0;
  lsum = dfs(i + 1, sum);
  a[i] = 1;
  rsum = dfs(i + 1, sum);
  return lsum + rsum;
}
