#include <bits/stdc++.h>
const long long INF = 1000000007;
using namespace std;
struct point {
  int x;
  int y;
};
long long gcd(long long a, long long b) {
  if (a > b) {
    return gcd(b, a);
  }
  return a == 0 ? b : gcd(b % a, a);
}
int lcm(int m, int n) {
  if ((0 == m) || (0 == n)) return 0;
  return ((m / gcd(m, n)) * n);
}
int input() {
  int x;
  cin >> x;
  return x;
}
int moji(char in) {
  int ans = (int)in - (int)'a';
  if ((ans < 0) || (ans > 25)) {
    ans = 26;
  }
  return ans;
}
const int VV = 1;
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s) {
  fill(d, d + VV, 100000);
  fill(used, used + VV, false);
  d[s] = 0;
  while (true) {
    cout << "Hello" << endl;
    int v = -1;
    for (int u = 0; u < VV; u++) {
      if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }
    if (v == -1) break;
    used[v] = true;
    for (int u = 0; u < VV; u++) {
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}
int compare_int(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int binary_searchh(long long x, long long k[], int n) {
  int l = 0;
  int r = n;
  while (r - l >= 1) {
    int i = (l + r) / 2;
    if (k[i] == x)
      return i;
    else if (k[i] < x)
      l = i + 1;
    else
      r = i;
  }
  return -1;
}
struct File {
  int aa;
  int bb;
  File(const int& aa, const int& bb) : aa(aa), bb(bb) {}
};
long long kaijo(long long x) {
  long long l = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7;
  long long sum = 1;
  for (int i = x; i > 0; i--) {
    sum *= i;
    if (sum > l) {
      sum %= l;
    }
  }
  return sum;
}
template <class T>
void chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
}
template <class T>
int former(const vector<T>& v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T>
int latter(const vector<T>& v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
struct UnionFind {
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (x == par[x]) {
      return x;
    }
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};
struct Edge {
  int a, b, cost;
  bool operator<(const Edge& o) const { return cost < o.cost; }
};
struct Graph {
  int n;
  vector<Edge> es;
  int kruskal() {
    sort(es.begin(), es.end());
    UnionFind uf(n);
    int min_cost = 0;
    for (int ei = 0; ei < es.size(); ei++) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }
    return min_cost;
  }
};
Graph input_graph() {
  Graph g;
  int m;
  cin >> g.n >> m;
  for (int i = 0; i < m; i++) {
    Edge e;
    cin >> e.a >> e.b >> e.cost;
    g.es.push_back(e);
  }
  return g;
}
long long labs(long long x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  int N, M;
  cin >> N >> M;
  int k[M];
  int s[11][11];
  for (int i = 0; i < 11; i++) {
    for (int j = 0; j < 11; j++) {
      s[i][j] = 0;
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  int p[M];
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int l[N];
    for (int j = 0; j < N; j++) {
      l[j] = 0;
    }
    for (int j = 0; j <= i; j++) {
      l[j] = 1;
    }
    sort(l, l + N);
    do {
      bool ok = true;
      for (int j = 0; j < M; j++) {
        int tmp = 0;
        for (int d = 0; d < k[j]; d++) {
          if (l[s[j][d]] == 1) {
            tmp++;
          }
        }
        if (tmp % 2 != p[j]) {
          ok = false;
        }
      }
      if (ok) {
        cnt++;
      }
    } while (next_permutation(l, l + N));
  }
  cout << cnt << endl;
}
