#include <bits/stdc++.h>
using namespace std;
long long modinv(long long a, long long mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}
template <int MOD>
struct Matrix {
  vector<vector<long long> > val;
  Matrix(int n, int m, long long x = 0) : val(n, vector<long long>(m, x)) {}
  void init(int n, int m, long long x = 0) {
    val.assign(n, vector<long long>(m, x));
  }
  size_t size() const { return val.size(); }
  inline vector<long long>& operator[](int i) { return val[i]; }
};
template <int MOD>
int GaussJordan(Matrix<MOD>& A, bool is_extended = false) {
  int m = A.size(), n = A[0].size();
  for (int row = 0; row < m; ++row)
    for (int col = 0; col < n; ++col)
      A[row][col] = (A[row][col] % MOD + MOD) % MOD;
  int rank = 0;
  for (int col = 0; col < n; ++col) {
    if (is_extended && col == n - 1) break;
    int pivot = -1;
    for (int row = rank; row < m; ++row) {
      if (A[row][col] != 0) {
        pivot = row;
        break;
      }
    }
    if (pivot == -1) continue;
    swap(A[pivot], A[rank]);
    auto inv = modinv(A[rank][col], MOD);
    for (int col2 = 0; col2 < n; ++col2)
      A[rank][col2] = A[rank][col2] * inv % MOD;
    for (int row = 0; row < m; ++row) {
      if (row != rank && A[row][col]) {
        auto fac = A[row][col];
        for (int col2 = 0; col2 < n; ++col2) {
          A[row][col2] -= A[rank][col2] * fac % MOD;
          if (A[row][col2] < 0) A[row][col2] += MOD;
        }
      }
    }
    ++rank;
  }
  return rank;
}
long long n, m, k[11], s[11][11], p[11], mod = 2;
void init() {
  cin >> n >> m;
  for (int i = 0; i < ((int)(m)); i++) {
    cin >> k[i];
    for (int j = 0; j < ((int)(k[i])); j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  for (int i = 0; i < ((int)(m)); i++) {
    cin >> p[i];
  }
}
int main(void) {
  init();
  Matrix<2> mt(m, n + 1);
  for (int i = 0; i < ((int)(m)); i++) {
    for (int j = 0; j < ((int)(k[i])); j++) {
      mt[i][s[i][j]] = 1;
    }
  }
  for (int i = 0; i < ((int)(m)); i++) mt[i][n] = p[i] % mod;
  long long t = n - GaussJordan(mt);
  cout << (t >= 0 ? (1 << t) : 0) << endl;
  return 0;
}
