#include <bits/stdc++.h>
using namespace std;
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  int cnt;
  cin.ignore();
  vector<vector<int>> data(M, vector<int>());
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      data.at(i).push_back(s);
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p.at(i);
  }
  int ans = 0;
  for (int bit = 1; bit < (1 << N + 1); bit++) {
    bool all = true;
    vector<int> S;
    for (int i = 1; i < N + 1; i++) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    for (int j = 0; j < M; j++) {
      for (int k = 0; k < S.size(); k++) {
        vector_finder(data.at(j), S.at(k));
        if (vector_finder == 0) all = false;
      }
    }
    if (all) cnt++;
  }
  cout << cnt << endl;
}
