#include <bits/stdc++.h>
int main(void) {
  int i, j, k, ans = 0;
  int n, m;
  scanf("%d%d", &n, &m);
  int num[11] = {}, switch_num, s[11][11] = {};
  for (i = 1; i <= m; i++) {
    scanf("%d", &num[i]);
    for (j = 0; j < num[i]; j++) {
      scanf("%d", &switch_num);
      for (k = 0;; k++) {
        if (s[switch_num][k] == 0) {
          s[switch_num][k] = i;
          break;
        }
      }
    }
  }
  int p[11] = {};
  for (i = 1; i <= m; i++) {
    scanf("%d", &p[i]);
  }
  int lamp[11] = {}, on[12] = {}, lamp_num = 0, flag = 0;
  while (1) {
    flag = 0;
    for (i = 1; i <= m; i++) {
      lamp[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      if (on[i] == 1) {
        for (j = 0;; j++) {
          lamp_num = s[i][j];
          if (lamp_num == 0) {
            break;
          }
          lamp[lamp_num] = (lamp[lamp_num] + 1) % 2;
        }
      }
    }
    for (i = 1; i <= m; i++) {
      if (lamp[i] != p[i]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      ans++;
    }
    on[1]++;
    for (i = 1;; i++) {
      if (on[i] == 2) {
        on[i] = 0;
        on[i + 1]++;
      } else {
        break;
      }
    }
    if (on[n + 1] == 1) {
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
