#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
vector<long long> v[100];
int main() {
  long long t, n, m, i, j, k, x = 0, y = 0, z = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> k;
    for (j = 0; j < k; j++) {
      cin >> z;
      v[i].push_back(z);
    }
  }
  for (i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
  }
  int ok = 0;
  for (i = 1; i <= m; i++) {
    if (v[i].size() == 1 && a[i] == 0) {
      ok = 1;
      break;
    } else {
      if (a[i] == 0) {
        b[v[i][0]] = 1;
        b[v[i][1]] = 1;
      } else {
        b[v[i][0]] = 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (b[i] == 0) {
      x++;
    }
  }
  if (ok == 1) {
    cout << 0 << endl;
    return 0;
  }
  cout << pow(2, n - x) << endl;
}
