#include <bits/stdc++.h>
using namespace std;
std::string join(const std::vector<int> &v, const std::string delim = "") {
  std::string result;
  for (unsigned int i = 0; i < v.size(); ++i) {
    result += std::to_string(v[i]);
    if (i != v.size() - 1) {
      result += delim;
    }
  }
  return result;
}
class Lamp {
 public:
  vector<int> *switches;
  int p;
};
vector<vector<int>> patterns;
void buildPatterns(vector<int> v, int count) {
  if (count == 0) {
    patterns.push_back(v);
  } else {
    vector<int> v1 = v;
    vector<int> v2 = v;
    v1.push_back(1);
    buildPatterns(v1, count - 1);
    v2.push_back(0);
    buildPatterns(v2, count - 1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<Lamp *> lamps;
  for (int i = 0; i < (int)(m); ++i) {
    int k;
    cin >> k;
    vector<int> *switches = new vector<int>;
    for (int j = 0; j < (int)(k); ++j) {
      int s;
      cin >> s;
      switches->push_back(s);
    }
    Lamp *l = new Lamp();
    l->switches = switches;
    lamps.push_back(l);
  }
  for (int i = 0; i < (int)(m); ++i) {
    int p;
    cin >> p;
    lamps[i]->p = p;
  }
  vector<int> v0;
  buildPatterns(v0, n);
  int ans = 0;
  for (int i = 0; i < (int)(patterns.size()); ++i) {
    bool ok = true;
    for (int j = 0; j < (int)(lamps.size()); ++j) {
      int sum = 0;
      Lamp *lamp = lamps[j];
      for (int k = 0; k < (int)(lamp->switches->size()); ++k) {
        int sno = lamp->switches->at(k);
        sum += patterns[i][sno - 1];
      }
      if (sum % 2 != lamps[j]->p) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
