#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sw(n, 0);
  int p = 0, ans = 0;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    while (x--) {
      int y;
      cin >> y;
      y--;
      sw[y] += (1 << i);
    }
  }
  for (auto&& u : sw) cout << u << ((&u < &sw.back()) ? " " : "\n");
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    p += (x << i);
  }
  for (int bit = 0; bit < 1 << n; bit++) {
    int tmp = 0;
    for (int i = 0; i < n; i++) {
      if (bit >> i & 1) tmp ^= sw[i];
    }
    if (tmp == p) ans++;
  }
  cout << ans << endl;
  return 0;
}
