#include <bits/stdc++.h>
using namespace std;
using in = int64_t;
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  vector<int> k(m);
  vector<vector<int>> s(m, vector<int>(0));
  for (in i = 0; i < (in)(m); i++) {
    cin >> k[i];
    for (in j = 0; j < (in)(k[i]); j++) {
      cin >> x;
      s[i].push_back(x - 1);
    }
  }
  vector<int> p(m);
  for (in i = 0; i < (in)(m); i++) cin >> p[i];
  int cnt = 0;
  int ans = 0;
  bool flag = false;
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<11> a(tmp);
    for (in i = 0; i < (in)(m); i++) {
      for (in j = 0; j < (in)(k[i]); j++) {
        if (a.test(s[i][j])) cnt++;
      }
      if (cnt % 2 != p[i]) {
        flag = true;
        break;
      }
    }
    if (flag) continue;
    ans++;
  }
  for (in i = 0; i < (in)(11 - m); i++) ans /= 2;
  cout << ans;
}
