#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vvi;
  vector<int> swch(N, 0);
  int k[M];
  int p[M];
  for (int i = 0; i < M; i++) {
    int h;
    cin >> h;
    k[i] = h;
    vvi.push_back(vector<int>());
    for (int j = 0; j < h; j++) {
      int s;
      cin >> s;
      vvi.back().push_back(s);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  int ans = 1;
  for (int i = 0; i < M; i++) {
    int h = k[i];
    for (int j = 0; j < h; j++) {
      if (swch[vvi[i][j] - 1] > 0) h--;
      swch[vvi[i][j] - 1]++;
    }
    ans *= pow(2, h - 1);
  }
  cout << ans << endl;
  return 0;
}
