#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

int main(){
  int n,m;
  cin>>n>>m;
  int x;
  vector<int> k(m);
  vec2(s,m,0);
  rep(i,m){
    cin>>k[i];
    rep(j,k[i]){
      cin>>x;
       s[i].push_back(x-1);
    }
  }
  vec(p,m);
  const num=n;
  int cnt=0;
  int ans=0;
  bool flag=false;
  
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
     bitset<n> a(tmp);
    rep(i,m){
       rep(j,k[i]){
          if(a.test(s[i][j])) cnt ++;
       }
      if(cnt%2!=p[i]){flag=true;break;}
    }
    if(flag) continue;
    ans ++;
  }
  cout<<ans;
}