#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M, vector<int>(0));
  for (int i = 0; i < (int)(M); i++) {
    cin >> k[i];
    for (int j = 0; j < (int)(k[i]); j++) {
      int num;
      cin >> num;
      num--;
      s[i].push_back(num);
    }
  }
  vector<int> p(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> p[i], p[i]--;
  }
  long long ans = 0;
  for (int i = 0; i < 1 << N; i++) {
    bool t = true;
    for (int j = 0; j < (int)(M); j++) {
      int num = 0;
      for (int k = 0; k < (int)(p[M]); k++) {
        if (i & s[j][k]) num++;
      }
      if (num != p[j]) {
        t = false;
        break;
      }
    }
    if (!t) {
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}
