#include <bits/stdc++.h>
int main() {
  int i, j, k, n, t, m, h, w, g;
  int f = 0;
  int o[12];
  int s[12][12];
  int p[12];
  int ii[15];
  int nn[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &o[i]);
    for (j = 0; j < o[i]; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &p[i]);
  }
  for (i = 0;; i++) {
    g = 0;
    for (j = 0; j < m; j++) {
      w = 0;
      for (k = 0; k < o[j]; j++) {
        w = w + nn[s[j][k] - 1];
      }
      if (p[j] == w % 2) {
        g++;
      }
    }
    if (g == m) {
      f++;
    }
    nn[0]++;
    for (j = 0; j < n - 1; j++) {
      if (nn[j] >= 2) {
        nn[j] = 0;
        nn[j + 1]++;
      }
      if (nn[n] == 1) {
        h = 1;
        break;
      }
    }
    if (h == 1) {
      break;
    }
  }
  printf("%d", f);
  return 0;
}
