#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M, vector<int>(10));
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < M; i++) cin >> p[i];
  int count = 0;
  int max = pow(2, N);
  for (int i = 0; i < max; i++) {
    stringstream ss;
    ss << bitset<10>(i);
    string swt = ss.str();
    cout << swt << endl;
    int f = 1;
    for (int j = 0; j < M; j++) {
      int tbit = 0;
      for (int l = 0; l < k[j]; l++) {
        tbit ^= swt[10 - s[j][l]] - '0';
      }
      if (tbit ^ p[j]) {
        f = 0;
        break;
      }
    }
    if (f) count++;
  }
  cout << count << endl;
  return 0;
}
