#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int n, m;
int k[10];
int s[10][10];
int p[10];
long long dfs(long long count, long long g, int j) {
  if (j == n) {
    long long ss[n];
    long long te = 10;
    long long temp1 = g;
    for (int i = 0; i < n; i++) {
      ss[i] = temp1 % 10;
      temp1 = temp1 / 10;
    }
    for (int i = 0; i < m; i++) {
      long long a = 0;
      for (int j = 0; j < k[i]; j++) {
        if (ss[s[i][j]] == 1) {
          a++;
        }
      }
      if (a % 2 != p[i]) return 0;
    }
    return 1;
  }
  long long temp = count + g;
  long long f = dfs(count * 10, temp, j + 1);
  long long b = dfs(count * 10, g, j + 1);
  return (f + b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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];
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  cout << dfs(1, 0, 0) << "\n";
}
