#include <bits/stdc++.h>
using namespace std;
const int MAX = 10;
int N = MAX;
int M = MAX;
vector<int> k(M);
vector<vector<int>> s(M, vector<int>(N));
vector<int> p(M);
int dfs(string date, int sum, int d, int count) {
  if (d == N) {
    int chk = 0;
    int t = dfs(date, sum, 1, count + 1);
    for (int l = 0; l < M; l++) {
      int chk2 = 0;
      for (int j = 0; j < k[l]; j++) {
        if (date[s[l][j]] == 'A') {
          chk2++;
        }
      }
      if (chk2 == k[l]) {
        chk++;
      }
    }
    if (chk == M) {
      sum++;
    }
  }
  if (count == pow(2, N)) {
    return sum;
  }
  date[d - 1] = 'A';
  int m = dfs(date, sum, d + 1, count);
  return m;
  date[d - 1] = 'B';
  int n = dfs(date, sum, d + 1, count);
  return n;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  string date;
  int ans = dfs(date, 0, 1, 0);
  cout << ans << endl;
}
