#include <bits/stdc++.h>
using namespace std;
int Rank(vector<vector<int>> A);
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> mat(M, vector<int>(N, 0));
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int k;
    cin >> k;
    for (int j = 0, j_len = (k); j < j_len; ++j) {
      int s;
      cin >> s;
      mat[i][s] = 1;
    }
  }
  vector<int> p(M);
  for (int i = 0, i_len = (M); i < i_len; ++i) cin >> p[i];
  int ans = 1;
  for (int i = 0, i_len = (N - Rank(mat)); i < i_len; ++i) {
    ans *= 2;
  }
  cout << ans << endl;
  return 0;
}
int Rank(vector<vector<int>> A) {
  const int n = A.size(), m = A[0].size();
  int r = 0;
  for (int i = 0; r < n && i < m; ++i) {
    int pivot = r;
    for (int j = r + 1; j < n; ++j) {
      if (abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
    }
    swap(A[pivot], A[r]);
    if (A[r][i] == 0) continue;
    for (int k = m - 1; k >= i; --k) {
      A[r][k] /= A[r][i];
    }
    for (int j = r + 1; j < n; ++j)
      for (int k = i; k < m; ++k) {
        A[j][k] -= A[r][k] * A[j][i];
      }
    ++r;
  }
  return r;
}
