#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k[m], p[m], s[m][n];
  fill(s[0], s[m], 0);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  bool switches[n + 1];
  fill(switches, switches + (n + 1), false);
  int ans = 0;
  do {
    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = 0; j < k[i]; j++) {
        sum += switches[s[i][j]];
      }
      if (sum / 2 != p[i]) break;
      if (i == m - 1) ans++;
    }
  } while (next_permutation(switches + 1, switches + (n + 1)));
  cout << ans << endl;
  return 0;
}
