#include <bits/stdc++.h>
using namespace std;
struct Lamp {
  vector<int> sws;
  bool even;
};
bool check(vector<bool>& sw, vector<Lamp>& lamps) {
  for (const Lamp& lamp : lamps) {
    int cnt = 0;
    for (const int s : lamp.sws) {
      if (sw[s]) ++cnt;
    }
    if (lamp.even && cnt % 2 == 1)
      return false;
    else if (!lamp.even && cnt % 2 == 0)
      return false;
  }
  return true;
}
void Log(bool debug, vector<bool>& sws) {
  if (debug) {
    cout << "(" << (sws[0] ? "on" : "off");
    for (size_t i = 1, size = sws.size(); i < size; ++i) {
      cout << "," << (sws[i] ? "on" : "off");
    }
    cout << ")";
  }
}
int backtrack(vector<bool>& sws, vector<bool>& fix, size_t idx,
              vector<Lamp>& lamps) {
  int cnt = 0;
  if (idx == sws.size() - 1) {
    int end = fix[idx] ? 1 : 2;
    for (int i = 0; i < end; ++i) {
      sws[idx] = i == 0;
      if (check(sws, lamps)) {
        ++cnt;
      }
    }
    return cnt;
  }
  if (!fix[idx]) {
    sws[idx] = true;
    cnt += backtrack(sws, fix, idx + 1, lamps);
    sws[idx] = false;
    cnt += backtrack(sws, fix, idx + 1, lamps);
  } else {
    int res = backtrack(sws, fix, idx + 1, lamps);
    cnt += res * 2;
  }
  return cnt;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<Lamp> lamps;
  vector<bool> fix(N, true);
  for (int m = 0; m < M; ++m) {
    int S;
    cin >> S;
    vector<int> sws;
    for (int s = 0; s < S; ++s) {
      int sw;
      cin >> sw;
      sws.push_back(sw - 1);
      fix[sw - 1] = false;
    }
    lamps.push_back(Lamp{sws, true});
  }
  for (int m = 0; m < M; ++m) {
    int ev;
    cin >> ev;
    lamps[m].even = ev == 0;
  }
  vector<bool> init_sws(N, true);
  cout << backtrack(init_sws, fix, 0, lamps) << endl;
  return 0;
}
