#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void Main() {
  int n, m;
  cin >> n >> m;
  bitset<10> each_bulb_p;
  vector<bitset<10>> switches(n);
  for (int i = 0; i < (int)(m); ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < (int)(k); ++j) {
      int x;
      cin >> x;
      x--;
      switches.at(x).set(i);
    }
  }
  for (int i = 0; i < (int)(m); ++i) {
    int p;
    cin >> p;
    each_bulb_p.set(p);
  }
  ll cnt;
  cnt = 0;
  for (int i = 0; i < (int)(1 << n); ++i) {
    bitset<10> bulbs_state;
    bitset<10> turned_switches;
    turned_switches = i;
    bulbs_state = each_bulb_p;
    for (int j = 0; j < (int)(10); ++j) {
      if (turned_switches.test(j)) {
        for (int k = 0; k < (int)(m); ++k) {
          if (switches.at(j).test(k)) bulbs_state.flip(k);
        }
      }
    }
    if (bulbs_state.count() == m) cnt++;
  }
  cout << cnt << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
}
