#include <bits/stdc++.h>
using namespace std;
int ans, n, m, p[10], k[10], d[10][10];
void dfs(int a[], int l) {
  if (l == n) {
    bool f = true;
    for (int i = 0; i < n; i++) {
      if (a[i] != p[i]) f = false;
    }
    if (f) ans++;
    return;
  }
  int aa[10];
  for (int i = 0; i < n; i++) aa[i] = a[i];
  for (int i = 0; i < n; i++) aa[i] = (aa[i] + d[l][i]) % 2;
  dfs(aa, l + 1);
  dfs(a, l + 1);
  return;
}
int main() {
  int s[10][10];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j]--;
      d[s[i][j]][i] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int a[10]{0};
  dfs(a, 0);
  cout << ans << endl;
}
