#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int ans = 0;
vector<long long int> p(10, 0);
vector<vector<long long int>> v;
void solve(vector<long long int> t, long long int i) {
  cout << i << endl;
  if (i == n) {
    for (long long int b = 0; b < m; b++) {
      if (t[b] != p[b]) return;
    }
    ans++;
    return;
  }
  solve(t, i + 1);
  for (auto k : v[i]) {
    t[k - 1]++;
  }
  solve(t, i + 1);
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  vector<long long int> c(10, 0);
  for (long long int i = 0; i < m; i++) {
    vector<long long int> temp;
    long long int q, k;
    cin >> k;
    for (long long int s = 0; s < k; s++) {
      long long int tt;
      cin >> tt;
      temp.push_back(tt);
    }
    v.push_back(temp);
  }
  for (long long int i = 0; i < m; i++) {
    cin >> p[i];
  }
  solve(c, 0);
  cout << ans << endl;
}
