#include <bits/stdc++.h>
using namespace std;
bool change_switch(vector<int> &switch_on, int N) {
  bool flag1 = false;
  for (int i = 0; i < N; i++) {
    if (switch_on.at(i) == 0) {
      flag1 = true;
    }
  }
  if (flag1 == false) {
    return false;
  }
  bool flag = false;
  switch_on.at(0) += 1;
  for (int i = 0; i < N; N++) {
    if (flag == true) {
      switch_on.at(i) += 1;
      flag = false;
    }
    if (switch_on.at(i) == 2) {
      flag = true;
      switch_on.at(i) = 0;
    } else {
      break;
    }
  }
  return true;
}
int main() {
  int N;
  int M;
  int count = 0;
  cin >> N >> M;
  vector<int> k(M, 0);
  vector<int> p(M, 0);
  vector<vector<int>> s;
  vector<int> switch_on(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++) {
      int b;
      cin >> b;
      s.at(i).push_back(b);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> p.at(i);
  }
  do {
    bool all_light = true;
    for (int i = 0; i < M; i++) {
      int c = 0;
      for (int j = 0; j < k.at(i); j++) {
        c += switch_on.at(s.at(i).at(j) - 1);
      }
      if (c % 2 != p.at(i)) {
        all_light = false;
        break;
      }
    }
    if (all_light == true) {
      count += 1;
    }
  } while (change_switch(switch_on, N));
  cout << count << endl;
  return 0;
}
