#include <bits/stdc++.h>
#//include <ext/pb_ds/assoc_container.hpp>
#//include <ext/pb_ds/tree_policy.hpp>
#//include <ext/pb_ds/detail/standard_policies.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//insert(), find_by_order(), order_of_key()
typedef long long int ll;
typedef unsigned long long int llu;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define ref(i,n) for(int i=0;i<n;++i)
#define rer(i,n) for(int i=n;i>=0;--i)
#define refv(i,n,k) for (int i = k; i <= n; ++i) 
#define rerv(i,n,k) for (int i = k; i >= n; --i) 
#define fi first
#define priority_queue_2 priority_queue <int, vector<int>, greater<int> >
#define se second
#define fast1 ios_base::sync_with_stdio(false)
#define fast2 cin.tie(NULL)
inline void pin(int n) { printf("%d\n",n);}
#define onec(x) __builtin_popcount(x);
#define all(x) x.begin(),x.end()
double PI = acos(-1);
const int inf =  0x3f3f3f3f;
#define sv()  int t; scanf("%d",&t); while(t--)
#define MOD 1000000007
#define TRACE
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
ll StoI(string &s){ll sum=0;for(ll i=0; i<s.size(); i++){s[i]-='0';sum=sum*10+s[i];}return sum;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
int n, m;
vector<int> b2s[50];
vector<int> s2b[50];
vector<int> onn(50);
int ans=0;
void solve(int x)
{
    int pos=1;
    int po=x;
    vector<int> co(25,0);
    while(x!=0)
    {
        if(x&1)
        {
            for(int i=0;i<s2b[pos].size();i++)
            co[s2b[pos][i]]++;
        }
        x/=2;
        pos++;
    }
    int nn=0;
    //cout << po << endl;
    for(int i=1;i<=m;i++)
    {
      //  cout << co[i] << " ";
        co[i]%=2;
        if(co[i]==onn[i])
            nn++;
    }
    //cout << endl;
    if(nn==m)
    {
        //cout << po << endl;
        ans++;
    }
}
// n= switch 
// m= bulb
int main()
{
    cin >> n >> m;
    int lim= pow(2,n);
    lim-=1;
    ref(i,m)
    {
        int l;
        cin >> l;
        ref(j,l)
        {
            int x;
            cin >> x;
            b2s[i+1].pb(x);
            s2b[x].pb(i+1);
        }
    }
    ref(i,m)
        cin >> onn[i+1];
    
    for(int i=0;i<=lim;i++)
    {
        solve(i);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256