#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int K[M][10];
  int detenai[N];
  for (int i = 0; i < N; i++) detenai[i] = -1;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < 10; j++) K[i][j] = -1;
  for (int i = 0; i < M; i++) {
    int kai;
    cin >> kai;
    for (int j = 0; j < kai; j++) {
      int s;
      cin >> s;
      s = s - 1;
      K[i][s] = 1;
      detenai[s] += 1;
    }
  }
  int p[M];
  for (int i = 0; i < M; i++) cin >> p[i];
  int kotae = 0;
  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    int gg[M];
    for (int i = 0; i < M; i++) gg[i] = 0;
    for (int j = 0; j < M; j++) {
      for (int i = 0; i < (int)S.size(); ++i) {
        if (K[j][S[i]] == 1) gg[j] += 1;
      }
    }
    int B[M];
    for (int i = 0; i < M; i++) B[i] = -1;
    for (int i = 0; i < M; i++) {
      if (gg[i] == 0)
        continue;
      else if (gg[i] % 2 == p[i])
        B[i] = 1;
    }
    bool ike = true;
    for (int i = 0; i < M; i++) {
      if (B[i] != 1) {
        ike = false;
        break;
      }
    }
    if (ike) {
      kotae++;
      cout << bit << ": {";
      for (int i = 0; i < (int)S.size(); ++i) {
        cout << S[i] << " ";
      }
      cout << "}" << endl;
    }
  }
  int mada = 0;
  for (int i = 0; i < N; i++) {
    if (detenai[i] == -1) mada += 1;
  }
  kotae = kotae * mada * 2;
  cout << kotae;
}
