#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (auto& e : s) {
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int tmp;
      cin >> tmp;
      e.push_back(tmp);
    }
  }
  vector<int> p(m);
  for (auto& e : p) cin >> e;
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    cout << bit << endl;
    bool flag = false;
    for (int i = 0; i < m; i++) {
      int count = 0;
      for (auto& e : s[i]) {
        if (bit & (1 << (e - 1))) count++;
      }
      cout << "k: " << i << " count: " << count << " p[i]: " << p[i] << endl;
      if (count % 2 != p[i]) {
        flag = true;
        break;
      }
      if (i == m - 1) {
        ans++;
      }
    }
    if (flag) continue;
  }
  cout << ans << endl;
  return 0;
}
