#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> swi(N, vector<int>(M + 13));
  vector<int> si(N, 0);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      a--;
      swi[a][si[a]] = i;
      si[a]++;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < si[i]; j++) {
      cout << swi[i][j] << ' ';
    }
    cout << endl;
  }
  vector<int> jud(M);
  for (int i = 0; i < M; i++) cin >> jud[i];
  int ans = 0;
  int bi[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
  for (int i_ = 0; i_ < bi[N]; i_++) {
    int i = i_;
    vector<int> num(M, 0);
    for (int j = 0; j < N; j++) {
      if (i % 2) {
        for (int k = 0; k < si[j]; k++) num[swi[j][k]]++;
      }
      i /= 2;
    }
    bool ok = true;
    for (int j = 0; j < M; j++) {
      if (num[j] % 2 != jud[j]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}
