#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k, s;
  int sw[10];
  for (int i = 0; i < m; i++) {
    sw[i] = 0;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      sw[i] |= 1 << s;
    }
  }
  int p;
  for (int i = 0; i < m; i++) {
    cin >> p;
    sw[i] |= p;
  }
  int pv = 0;
  int pv_index, tmp;
  int not_resolve = 0;
  for (int mask = 1 << n; mask != 1; mask >>= 1) {
    pv_index = -1;
    for (int j = pv; j < m; j++) {
      if (sw[j] & mask) {
        if (pv_index == -1)
          pv_index = j;
        else {
          sw[j] ^= sw[pv_index];
          if (sw[j] == 1) {
            not_resolve = 1;
            break;
          }
        }
      }
    }
    if (pv_index != -1) {
      tmp = sw[pv_index];
      sw[pv] = sw[pv_index];
      sw[pv_index] = tmp;
      pv++;
    }
    if (not_resolve) break;
  }
  int result;
  if (not_resolve)
    result = 0;
  else {
    result = 1;
    for (int i = pv; i < n; i++) result *= 2;
  }
  cout << result << endl;
  return 0;
}
