#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> a[m];
  for (int i = 0; i < m; ++i) {
    long long k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      long long x;
      cin >> x;
      a[i].push_back(x);
    }
  }
  long long p[m];
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }
  long long ans = 0;
  set<long long> s[m];
  long long c = 0;
  for (int i = 0; i < a[0].size(); ++i) {
    s[0].insert(a[0][i]);
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < a[i].size(); j++) {
      if (s[i - 1].count(a[i][j]) > 0) {
        s[i].insert(a[i][j]);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (p[i] % 2 == 0) {
      if (a[i].size() < 2) {
        cout << 0 << endl;
        return 0;
      }
      ans += 2;
    } else {
      if (a[i].size() < 1) {
        cout << 0 << endl;
        return 0;
      }
      ans++;
    }
  }
  if (s[m - 1].size() == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (ans > m && s[m - 1].size() >= 2) {
    ans = n - 2;
  }
  if (ans == m && s[m - 1].size() >= 1) {
    ans = n - 1;
  }
  if (ans > m && s[m - 1].size() == 1) {
    ans = n - (ans - (m - 1));
  }
  cout << pow(2, ans) << endl;
  return 0;
}
