#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,answer = 0;
    cin >> N >> M;
    vector<int> pettern(10);
    vector<vector<int>> lump(M,vector<int>(0,0));
    vector<int> check(M);
    REP(i,M){
        int xa;
        cin >> xa;
        REP(l,xa){
            int ga;
            cin >>ga;
            ga--;
            lump.at(i).push_back(ga);
        }
    }
    REP(i,M)cin >> check.at(i);
    if(N == 10){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2)REP(f,2)REP(g,2)REP(h,2)REP(i,2)REP(j,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        pettern.at(5) = f;
        pettern.at(6) = g;
        pettern.at(7) = h;
        pettern.at(8) = i;
        pettern.at(9) = j;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 9){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2)REP(f,2)REP(g,2)REP(h,2)REP(i,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        pettern.at(5) = f;
        pettern.at(6) = g;
        pettern.at(7) = h;
        pettern.at(8) = i;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 8){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2)REP(f,2)REP(g,2)REP(h,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        pettern.at(5) = f;
        pettern.at(6) = g;
        pettern.at(7) = h;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 7){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2)REP(f,2)REP(g,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        pettern.at(5) = f;
        pettern.at(6) = g;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 6){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2)REP(f,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        pettern.at(5) = f;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 5){REP(a,2)REP(b,2)REP(c,2)REP(d,2)REP(e,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        pettern.at(4) = e;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 4){REP(a,2)REP(b,2)REP(c,2)REP(d,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        pettern.at(3) = d;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 3){REP(a,2)REP(b,2)REP(c,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        pettern.at(2) = c;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 2){REP(a,2)REP(b,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}else if(N == 1){REP(a,2)REP(b,2){
        pettern.at(0) = a;
        pettern.at(1) = b;
        REP(k,M){
            int imat = 0;
            REP(l,lump.at(k).size()){
                imat += pettern.at(lump.at(k).at(l));
            }
            imat = imat%2;
            if(imat != check.at(k))break;
            if(k == M-1)answer++;
        }
    }}
    cout <<answer<< "\n";
}

Measured memory_bytes: 256