#include <bits/stdc++.h>
const long long LINF = 1e18;
const int INF = 1e8;
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m, vector<int>());
  int tmp;
  for (int i = 0; i < (m); i++) {
    cin >> k[i];
    for (int j = 0; j < (k[i]); j++) {
      cin >> tmp;
      s[i].push_back(tmp - 1);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < (m); i++) {
    cin >> p[i];
  }
  vector<int> i(10);
  int tmpAns = 0;
  int tmpAns2 = 0;
  int ans = 0;
  for (i[0] = 0; i[0] < 2; i[0]++) {
    for (i[1] = 0; i[1] < 2; i[1]++) {
      if (n <= 1 && i[1] == 1) {
        break;
      }
      for (i[2] = 0; i[2] < 2; i[2]++) {
        if (n <= 2 && i[2] == 1) {
          break;
        }
        for (i[3] = 0; i[3] < 2; i[3]++) {
          if (n <= 3 && i[3] == 1) {
            break;
          }
          for (i[4] = 0; i[4] < 2; i[4]++) {
            if (n <= 4 && i[4] == 1) {
              break;
            }
            for (i[5] = 0; i[5] < 2; i[5]++) {
              if (n <= 5 && i[5] == 1) {
                break;
              }
              for (i[6] = 0; i[6] < 2; i[6]++) {
                if (n <= 6 && i[6] == 1) {
                  break;
                }
                for (i[7] = 0; i[7] < 2; i[7]++) {
                  if (n <= 7 && i[7] == 1) {
                    break;
                  }
                  for (i[8] = 0; i[8] < 2; i[8]++) {
                    if (n <= 8 && i[8] == 1) {
                      break;
                    }
                    for (i[9] = 0; i[9] < 2; i[9]++) {
                      if (n <= 9 && i[9] == 1) {
                        break;
                      }
                      for (int j = 0; j < m; j++) {
                        for (int j2 = 0; j2 <= k[j]; j2++) {
                          tmpAns += i[s[j][j2]];
                        }
                        if (tmpAns % 2 == p[j]) {
                          tmpAns2++;
                          if (tmpAns2 == m) {
                            ans++;
                            tmpAns = 0;
                            tmpAns2 = 0;
                          } else {
                            continue;
                          }
                        } else {
                          tmpAns = 0;
                          tmpAns2 = 0;
                          break;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
