#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, counter, counter1, answer = 0;
  int y = 0;
  cin >> N >> M;
  int p[M];
  for (int tmp = 0; tmp < (1 << 20); tmp++) {
    bitset<20> s(tmp);
    cin >> counter;
    for (int j = 0; j < M; j++) {
      for (int i = 0; i < counter; i++) {
        cin >> counter1;
        if (s.test(counter1)) {
          answer++;
        }
      }
      if (answer % 2 == 1) {
        p[j] = 1;
      }
      answer = 0;
    }
    int aaa = 0;
    for (int i = 0; i < M; i++) {
      cin >> counter1;
      if (p[i] == counter1) {
        aaa++;
      }
    }
    if (aaa == M) y++;
  }
  cout << y << endl;
}
