#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;


int N, M;
vector<int> pattern;
vector<vector<int>> switchs;

bool check(vector<int> target_vect){
  rep(i, M){
    if(target_vect[i] != pattern[i]) return false;
  }
  return true;
}

int solve(int depth, vector<int> current_vect){


  if(depth == N){
    if(check(current_vect)) return 1;
    return 0;
  }

  int skipped = solve(depth+1, current_vect);

  vector<int> applied_vect(M, 0);

  rep(i, M){
    applied_vect[i] = (current_vect[i] + switchs[depth][i]) % 2;
  }

  int not_skipped = solve(depth+1, applied_vect);

  return skipped + not_skipped;
}


signed main(){
  cin >> N >> M;

  // input
  vector<vector<int>> tmp_switchs(N, vector<int>(M, 0));

  rep(i, M){
    int k;
    cin >> k;
    rep(j, k){
      int s;
      cin >> s;
      s--;
      tmp_switchs[s][i] = 1;
    }
  }

  switchs = tmp_switchs;

  vector<int> tmp_vect(M, 0);
  rep(i, M){
    cin >> tmp_vect[i];
  }

  pattern = tmp_vect;

  vector<int> tmp_vect2(M, 0);
  cout << solve(0, tmp_vect2) << endl;

  return 0;
}


Measured memory_bytes: 256