#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
int main() {
  int n, m, ans = 0, c = 0;
  cin >> n >> m;
  vector<vector<int>> q(m);
  for (int(i) = 0; (i) < (m); (i)++) {
    int p;
    cin >> p;
    c ^= (p << i);
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    int k;
    cin >> k;
    q[i].assign(k, 0);
    for (int(j) = 0; (j) < (k); (j)++) cin >> q[i][j];
  }
  for (int(i) = 0; (i) < ((1 << n)); (i)++) {
    int cnt = 0;
    for (int(j) = 0; (j) < (m); (j)++)
      for (int(k) = 0; (k) < (q[j].size()); (k)++) {
        if (i & (1 << (q[j][k] - 1))) cnt ^= (1 << j);
      }
    if (c == cnt) ans++;
  }
  cout << ans << endl;
}
