#include <bits/stdc++.h>
using namespace std;
bool Pairsecond(const pair<int, int>& pf, pair<int, int>& ps) {
  return pf.second < ps.second;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> canse;
  for (int i = 0; pow(2, n) > i; i++) {
    canse.push_back(i);
  }
  vector<int> a[m];
  for (int i = 0; m > i; i++) {
    int k;
    cin >> k;
    for (int j = 0; k > j; j++) {
      int tmp;
      cin >> tmp;
      a[i].push_back(tmp);
    }
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; m > i; i++) {
    int wari;
    cin >> wari;
    for (int j = 0; canse.size() > j; j++) {
      int nw = pow(2, n - 1);
      int l = 1;
      int aok = a[i][0];
      int nwaok = 0;
      int kosu = 0;
      int ima = canse[j];
      while (nw != 0) {
        if (l == aok) {
          if (ima / nw == 1) kosu++;
        }
        ima = ima % nw;
        nw /= 2;
        if (l == aok) {
          nwaok++;
          aok = a[i][nwaok];
        }
        l++;
      }
      if (kosu % 2 != wari) {
        canse.erase(canse.begin() + j);
        j--;
      }
    }
  }
  cout << canse.size() << endl;
  return 0;
}
