#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long;
void combination(vector<vector<int>> &v, int n, int r) {
  std::string bit_mask(r, 1);
  bit_mask.resize((unsigned long)n, 0);
  int c = 0, j;
  do {
    j = 0;
    for (int i = 0; i < n; ++i) {
      if (bit_mask[i]) {
        v[c][j++] = i;
      }
    }
    c++;
  } while (std::prev_permutation(bit_mask.begin(), bit_mask.end()));
}
long ncr(int n, int r) {
  long a = 1;
  r = r > n - r ? n - r : r;
  for (int i = 1; i <= r; i++, n--) {
    if (n % i == 0) {
      a *= n / i;
    } else if (a % i == 0) {
      a = a / i * n;
    } else {
      a = (a * n) / i;
    }
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  auto k = vector<int>(m);
  auto s = vector<vector<int>>(m);
  auto p = vector<int>(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    auto v = vector<int>(k[i]);
    for (int j = 0; j < k[i]; j++) {
      cin >> v[j];
    }
    s[i] = v;
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  vector<vector<int>> ra;
  for (int i = 0; i < n + 1; i++) {
    int iv = ncr(n, n - i);
    auto ra_tmp = vector<vector<int>>(iv, vector<int>(n));
    combination(ra_tmp, n, (n - i));
    copy(ra_tmp.begin(), ra_tmp.end(), back_inserter(ra));
  }
  for (int i = 0; i < m; i++) {
    vector<vector<int>> rr;
    copy_if(ra.begin(), ra.end(), back_inserter(rr),
            [p, i, s, n, k](vector<int> v) {
              int sum = 0;
              for (int j = 0; j < k[i]; j++) {
                sum += v[s[i][j] - 1];
              }
              return p[i] == sum % 2;
            });
    ra = rr;
  }
  cout << ra.size() << endl;
  return 0;
}
