using System;
using System.Collections.Generic;
namespace I_am_the_brown_coder{
    class ABC10000000{
        static void Main(){
            string[] n_m = Console.ReadLine().Split();
            int n = int.Parse(n_m[0]);
            int m = int.Parse(n_m[1]);
            List<int>[] sw = new List<int>[n];
            for(int i=0;i<n;i++){
                sw[i] = new List<int>();
            }
            for(int i=0;i<m;i++){
                string[] input = Console.ReadLine().Split();
                for(int j=0;j<int.Parse(input[0]);j++){
                    sw[int.Parse(input[j+1])-1].Add(i);
                }
            }
            string[] ps = Console.ReadLine().Split();
            int[] p = new int[m];
            for(int i=0;i<m;i++){
                p[i] = int.Parse(ps[i]);
            }
            int ons = 0;
            bool[] dnonoff = new bool[m];
            for(int i =0;i<m;i++){
                if(p[i]==0){
                    dnonoff[i] = true;
                    ons ++;
                }
            }
            int ans = 0;
            Stack<int[]> st = new Stack<int[]>();
            st.Push(new int[]{0,0});
            st.Push(new int[]{0,1});
            while(st.Count>0){
                int[] ima = st.Pop();
                if(ima[1]>0){
                    foreach(int i in sw[ima[0]]){
                        dnonoff[i] = !dnonoff[i];
                        if(dnonoff[i]){
                            ons ++;
                        }else{
                            ons --;
                        }
                    }
                }
                if(ima[0]==n-1){
                    if(ons==m){
                        ans += 1;
                    }
                    if(ima[1]>0){foreach(int i in sw[ima[0]]){
                        dnonoff[i] = !dnonoff[i];
                        if(dnonoff[i]){
                            ons ++;
                        }else{
                            ons --;
                        }
                    }}
                }else{
                    st.Push(new int[]{ima[0]+1,1});
                    st.Push(new int[]{ima[0]+1,0});
                    
                }
            }

            Console.WriteLine(ans);
        }

    }
}