#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  cout << '[';
  for (int i = 0, _i = (((int)(v).size())); i < _i; i++) cout << v[i] << ",";
  cout << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
int N, S;
int T[10];
int R;
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> N >> S;
  for (int i = 0, _i = (S); i < _i; i++) {
    int t;
    cin >> t;
    for (int j = 0, _j = (t); j < _j; j++) {
      int p;
      cin >> p;
      T[p - 1] |= (1 << i);
    }
  }
  for (int i = 0, _i = (S); i < _i; i++) {
    int p;
    cin >> p;
    R |= p << i;
  }
  int res = 0;
  for (int i = 0, _i = (1 << N); i < _i; i++) {
    int c = 0;
    for (int j = 0, _j = (S); j < _j; j++)
      if (i & (1 << j)) c ^= T[j];
    if (c == R) res++;
  }
  cout << res << '\n';
}
