#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << endl;
    os << v[i];
  }
  return os;
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> k(m);
  vector<vector<ll>> s(m, vector<ll>(n));
  for (ll i = (0), __last_i = (m); i < __last_i; i++) {
    cin >> k[i];
    for (ll j = (0), __last_j = (k[i]); j < __last_j; j++) cin >> s[i][j];
  }
  vector<ll> p(m);
  for (ll i = (0), __last_i = (m); i < __last_i; i++) cin >> p[i];
  vector<ll> ss(m);
  for (ll i = (0), __last_i = (m); i < __last_i; i++) {
    for (ll j = (0), __last_j = (k[i]); j < __last_j; j++)
      ss[i] += (ll(1) << s[i][j] - 1);
  }
  ll pp = 0;
  for (ll i = (0), __last_i = (m); i < __last_i; i++) {
    pp += p[i] * (ll(1) << i);
  }
  ll ans = 0;
  for (ll i = (1), __last_i = ((ll(1) << n)); i < __last_i; i++) {
    ll nor = 0;
    for (ll j = (0), __last_j = (m); j < __last_j; j++) {
      ll nornor = 0;
      for (ll k = (0), __last_k = (n); k < __last_k; k++) {
        if (((ss[j] >> k) % 2) == ((i >> k) % 2)) {
          nornor++;
        }
      }
      nornor %= 2;
      nor += nornor * (ll(1) << j);
    }
    if (pp == nor) {
      ans++;
    }
  }
  cout << ans << endl;
}
