#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
const long long MOD = long long(1e9 + 7);
const long long INF = long long(1e18) + 7;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
unsigned GetDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
unsigned binarySearch(long long target, long long max, long long min) {
  while ((max - min) > 1) {
    if ((max + min) / 2 > target) {
      max = (max + min) / 2;
      min = min;
    } else {
      max = max;
      min = (max + min) / 2;
    }
  }
}
void f(int rest, string s) {
  char abc[] = "abc";
  if (rest == 0) {
    cout << s << endl;
  } else {
    for (int i = 0; i < 3; i++) {
      f(rest - 1, s + abc[i]);
    }
  }
}
struct UnionFind {
  vector<long long> par;
  map<long long, long long> s;
  UnionFind(long long n) : par(n) {
    for (long long i = 0; i < n; i++) {
      par[i] = i;
      s[i]++;
    }
  }
  long long root(long long x) {
    if (par[x] == x) return x;
    return root(par[x]);
  }
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) return;
    if (size(rx) > size(ry)) {
      s[rx] = s[rx] + s[ry];
      par[root(y)] = rx;
    } else {
      s[ry] = s[ry] + s[rx];
      par[root(x)] = ry;
    }
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return s[root(x)]; }
};
long long mod_pow(long long base, long long exp) {
  if (exp == 1) return base % MOD;
  if (exp % 2 == 1) return (base * mod_pow(base, exp - 1)) % MOD;
  long long t = mod_pow(base, exp / 2);
  return (t * t) % MOD;
}
long long mod_permutation(long long n, long long r) {
  long long t = 1;
  while (r != 0) {
    t = (t % MOD) * (n % MOD);
    n--;
    r--;
  }
  return t;
}
long long mod_factorial(long long r) {
  long long v = 1;
  while (r != 0) {
    v = (v % MOD) * (r % MOD);
    r--;
  }
  return v;
}
struct Node {
  vector<long long> edges;
  vector<long long> costs;
  bool done;
  long long cost;
  friend bool operator<(const Node& lhs, const Node& rhs) {
    return rhs.cost < lhs.cost;
  }
};
long long mod_conb() {}
int main() {
  long long n, m;
  cin >> n >> m;
  long long k;
  long long s;
  vector<vector<long long>> sk;
  vector<bool> p;
  for (long long i = 0; i < m; i++) {
    cin >> k;
    vector<long long> sm(n, 0);
    for (long long j = 0; j < k; j++) {
      cin >> s;
      sm[s - 1] = 1;
    }
    sk.push_back(sm);
  }
  bool pi;
  for (long long i = 0; i < m; i++) {
    cin >> pi;
    p.push_back(pi);
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < sk[i].size(); j++) {
    }
  }
  long long ma = 0;
  for (long long j = 0; j < n; j++) {
    for (long long i = 0; i < m; i++) {
      long long c = 0;
      for (long long bit = 0; bit < (1 << n); bit++) {
        for (long long j = 0; j < sk[i].size(); j++) {
          if (bit & (1 << j)) {
            if (sk[i][j]) c++;
          } else {
          }
        }
      }
      if (c % 2 == p[j]) ma++;
    }
  }
  cout << ma;
  return 0;
}
