#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k[11];
  int s[11][11];
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  int p[11];
  for (int i = 0; i < m; i++) cin >> p[i];
  int total[11];
  for (int i = 0; i < m; i++) {
    if (k[i] == 1 && p[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    int p_v;
    if (k[i] % 2 == 0) {
      if (p[i] == 0) {
        total[i] = k[i] * ((k[i] - 1) / 2) + 1 + ((k[i] - 1) / 2) % 2;
      } else {
        total[i] = k[i] * ((k[i]) / 2);
      }
    } else {
      if (p[i] == 0) {
        total[i] = k[i] * ((k[i]) / 2) + 1;
      } else {
        total[i] = k[i] * ((k[i]) / 2) + k[i] % 2;
      }
    }
  }
  int total_prod = 1;
  for (int i = 0; i < m; i++) total_prod *= total[i];
  cout << total_prod << endl;
}
