#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m, on = 0;
  cin >> n >> m;
  vector<long long> bulb(m);
  for (long long i = 0; i < (long long)m; ++i) {
    long long k;
    cin >> k;
    for (long long j = 0; j < (long long)k; ++j) {
      long long bit;
      cin >> bit;
      bulb[i] ^= (1 << (bit - 1));
    }
  }
  for (long long i = 0; i < (long long)m; ++i) {
    long long bit;
    cin >> bit;
    if (bit) on ^= (1 << bit);
  }
  long long ans = 0;
  for (long long mask = 0; mask < (long long)(1 << n); ++mask) {
    long long curon = 0;
    for (long long bit = 0; bit < (long long)n; ++bit)
      if (mask & (1 << bit))
        for (long long i = 0; i < (long long)m; ++i)
          if (bulb[i] & (1 << bit)) curon ^= (1 << i);
    ans += (on == curon);
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
