#include <bits/stdc++.h>
using namespace std;
struct ff {
  int x;
  int a[15];
} f[15];
int main() {
  int n, m, i, j, v, l;
  int p[i];
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &f[i].x);
    for (j = 0; j < f[i].x; j++) scanf("%d", &f[i].a[j]);
  }
  for (i = 0; i < m; i++) scanf("%d", &p[i]);
  sort(p, p + m);
  int b[] = {0};
  int o[] = {0};
  for (i = 0, v = 0, l = 0; i < m; i++) {
    if (p[i] == 0) {
      for (j = 0; j < f[i].x; j++) {
        b[v] = f[i].a[j];
        v++;
      }
    }
    if (p[i] == 1) {
      for (j = 0; j < f[i].x; j++) {
        o[l] = f[i].a[i];
        l++;
      }
    }
  }
  int sum1[15];
  for (i = 0; i < n; i++) sum1[i] = i + 1;
  for (i = 0; i < v; i++)
    if (sum1[b[i] - 1] != 0) sum1[b[i] - 1] = 0;
  int sum2 = 0;
  for (i = 0; i < l; i++)
    if (sum1[o[i] - 1] != 0) sum2++;
  int h = 1;
  for (i = 1; i <= sum2; i++) h = h * 2;
  printf("%d\n", h);
  return 0;
}
