#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      vec[i].push_back(x);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int count = 0;
  for (int i = 0; i < (1 << m); ++i) {
    vector<int> on;
    for (int j = 0; j < m; ++j) {
      if (i & (1 << j)) {
        on.push_back(j);
      }
    }
    vector<int> key;
    bool flag = true;
    for (int c : on) {
      set_intersection(vec[c].begin(), vec[c].end(), on.begin(), on.end(),
                       inserter(key, key.end()));
      for (int i : key) {
        cout << i;
      }
      cout << endl;
      if (key.size() % 2 != p[c] && key.size() > 0) {
        flag = false;
        break;
      } else
        key.clear();
    }
    if (flag) count++;
    on.clear();
  }
  cout << (count) << endl;
  return 0;
}
