#include <bits/stdc++.h>
using namespace std;
int a[15];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, k, s;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      a[s] |= (1 << i);
    }
  }
  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    cin >> s;
    ans <<= 1;
    ans |= s;
  }
  int cnt = 0;
  for (int i = 0; i < (1 << n); i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      int cur = i >> j;
      if (cur & 1) tmp ^= a[j + 1];
    }
    if (tmp == ans) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
