using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
    int[] swden = inta();
    int[,] map = new int[11,11];
    for(int i=0;i<swden[1];i++){
        int[] judge = inta();
        for(int j=0;j<judge[0]+1;j++){
            map[i,j] = judge[j];
        }
    }
    int[] judge2 = inta();
    int[] onoff = new int[swden[0]];
    int ans = 0;
    
    while(onoff[swden[0]-1] < 2){
        int oncheck = 0;
        for(int i=0;i<swden[1];i++){
            int counter = 0;
            
            for(int j=0;j<map[i,0];j++){
                if(onoff[j] == 1){
                    WriteLine(j);
                    counter++;
                }
            }
            
            
            if(counter %2 == judge2[i]){
                oncheck++;
                WriteLine($"{onoff[0]} {onoff[1]}:");
            }
        }
        if(oncheck == swden[1]){
            ans++;
        }
        onoff[0]++;
        for(int i=0;i<swden[0]-1;i++){
            if(onoff[i] == 2){
                onoff[i+1]++;
                onoff[i] = 0;
            }
        }
    }
    
    WriteLine(ans);
    
    
    
    
    
    }
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
    static int[,] inta2(int num_array,int in_array){
        int[,] int_array2 = new int[num_array,in_array];
        for(int i=0;i<num_array;i++){
            int[] temp_array = inta();
            for(int j=0;j<in_array;j++){
                int_array2[i,j] = temp_array[j];
            }
        }
        return int_array2;
    }
}