#include <iostream>
#include <tuple>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<(int)(n); i++)

int s[10];

int count(int n, int p) {
  if(n <= 0) return p == 0;
  else return count(n-1, p ^ s[n-1]) + count(n-1, p);
}

int main() {
  int n, m, p = 0;
  cin >> n >> m;
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int b;
      cin >> b;
      s[b-1] += 1 << i;
    }
  }
  rep(i,m) {
    int b;
    cin >> b;
    p += b << i;
  }
  
  cout << count(n, p) << endl;
  return 0;
}