#include <bits/stdc++.h>
using namespace std;
int a[50][50];
int b[50];
int vis[50];
int p[50];
int C(int x, int y) {
  if (x == y) return 1;
  int ans = 1;
  for (int i = 1; i <= x; i++) {
    ans *= i;
  }
  int re = 1;
  for (int i = 1; i <= y; i++) re *= i;
  for (int i = 1; i <= x - y; i++) re *= i;
  return ans / re;
}
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    for (int j = 0; j < b[i]; j++) cin >> a[i][j], vis[a[i][j]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (p[i] == 0) {
      int sum = 0;
      for (int j = 2; j <= b[i]; j += 2) {
        sum += C(b[i], j);
      }
      ans *= sum;
    } else if (p[i] == 1) {
      int sum = 0;
      for (int j = 1; j <= b[i]; j += 2) sum += C(b[i], j);
      ans *= sum;
    }
  }
  int couts = 0;
  for (int i = 1; i <= m; i++) {
    if (vis[i] == 0) couts++;
  }
  if (couts != 0)
    cout << (long long)ans * couts * 2 << endl;
  else
    cout << ans << endl;
  return 0;
}
