#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int p = 0;
  vector<int> connect(N);
  for (int i = (int)(0); i < (int)(M); ++i) {
    int k;
    cin >> k;
    for (int j = (int)(0); j < (int)(k); ++j) {
      int s;
      cin >> s;
      --s;
      connect[s] |= (1 << i);
    }
  }
  for (int i = (int)(0); i < (int)(M); ++i) {
    int x;
    cin >> x;
    p |= (1 << x);
  }
  int ans = 0;
  for (int i = (int)(0); i < (int)((1 << N)); ++i) {
    int t = 0;
    for (int j = (int)(0); j < (int)(N); ++j) {
      if ((i >> j) & 1) {
        t ^= connect[j];
      }
    }
    if (t == p) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
