#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <typename T>
using vec = vector<T>;
template <typename T>
using vec2 = vec<vec<T>>;
template <typename T>
using vec3 = vec<vec2<T>>;
template <typename T>
using vec4 = vec<vec3<T>>;
template <typename T>
using vec5 = vec<vec4<T>>;
template <typename T>
inline istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
template <typename V, typename H>
void resize(vector<V>& _v, const H _h) {
  _v.resize(_h);
}
template <typename V, typename H, typename... T>
void resize(vector<V>& _v, const H& _h, const T&... _t) {
  _v.resize(_h);
  for (auto& __v : _v) resize(__v, _t...);
}
template <typename V, typename T>
typename enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) {
  std::fill(begin(_v), end(_v), _t);
}
template <typename V, typename T>
typename enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) {
  for (auto& _e : _v) fill(_e, _t);
}
template <typename T>
inline void UNIQUE(vector<T>& _v) {
  sort(begin(_v), end(_v));
  _v.erase(unique(begin(_v), end(_v)), _v.end());
}
struct pre_ {
  pre_() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(8);
  }
} pre__;
int main(void) {
  int N, M;
  cin >> N >> M;
  vec<int> bulb(N);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int s;
      cin >> s;
      --s;
      bulb[s] |= 1 << i;
    }
  }
  int P = 0;
  for (int i = 0; i < M; ++i) {
    int p;
    cin >> p;
    if (p) P |= 1 << p;
  }
  int ans = 0;
  for (int b = 0; b < (1 << N); ++b) {
    int res = 0;
    for (int i = 0; i < N; ++i) {
      if (b & (1 << i)) {
        res ^= bulb[i];
      }
    }
    if (res == P) ++ans;
  }
  cout << ans << endl;
  return 0;
}
