#include <bits/stdc++.h>
using namespace std;
int n, m;
int k[11], s[11][11], p[11], t[11];
int tmp = 0, res = 0;
void Solve() {
  cin >> n >> m;
  int i = 1;
  while (i <= m) {
    int flag = 0;
    cin >> k[i];
    for (int j = 1; j <= k[i]; j++) cin >> s[i][j];
    i++;
  }
  for (int j = 1; j <= m; j++) {
    if (k[j] == 1) t[s[j][1]] = 1;
  }
  for (int j = 1; j <= n; j++) {
    if (t[j] == 1) res++;
  }
  for (int j = 1; j <= m; j++) {
    int flag = 0;
    for (int w = 1; w <= k[j]; w++) {
      if (t[s[j][w]] > 0) flag = 1;
    }
    if (flag == 0) res++;
  }
  for (int j = 1; j <= m; j++) {
    cin >> p[j];
    if (p[j] == 1) tmp++;
  }
  int s1 = 1, s2 = 1;
  for (int j = 1; j <= res; j++) s1 *= j;
  for (int j = tmp; j > tmp - res; j--) s2 *= j;
  int ans = s2 / s1;
  if (res < tmp)
    cout << 0 << endl;
  else if (res == tmp)
    cout << 1 << endl;
  else if (res > tmp)
    cout << ans << endl;
}
int main() {
  Solve();
  return 0;
}
