using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	private static int Cnt=0;
	private static Dictionary<String,int> Ora=new Dictionary<String,int>();
	public static void Main(string[] args)
	{
		string[] k = Console.ReadLine().Split(' ');
		int n = int.Parse(k[0]);
		int m = int.Parse(k[1]);
		List<Bolb> bolbs=new List<Bolb>();
		bool[] sw=new bool[n];
		
		for(int i = 0; i < m; i ++)
		{
			string[] s = Console.ReadLine().Split(' ');
			Bolb b = new Bolb();
			for(int j = 0; j < s.Length;j++)
			{
				int num=int.Parse(s[j]);
				if(j==0)
				{
					b.Connecting=num;
					continue;
				}
				b.Switches.Add(num-1);
			}
			bolbs.Add(b);
			
		}
		string[] t = Console.ReadLine().Split(' ');
		for(int i = 0; i < t.Length;i++)
		{
			bolbs[i].Amari=int.Parse(t[i]);
		}
		
		
		Sousa(0,bolbs,sw);
		Console.WriteLine(Cnt);
	}
	
	private static void Sousa(int i, List<Bolb> bolbs, bool[] sw)
	{
		if(i>sw.Length)
			return;
		string str=ToStr(sw);
		if(!Ora.ContainsKey(str))
		{
		Console.WriteLine(str);
		Ora.Add(str,1);
		bool p=true;
		foreach(Bolb k in bolbs)
		{
			if(!k.IsLight(sw))
			{
				p=false;
				break;
			}
		}
		
		if(p)
		{
			Cnt++;
		}
		}
				if(i>=sw.Length)
			return;

			sw[i]=false;
			Sousa(i+1,bolbs,sw);
			sw[i]=true;
			Sousa(i+1,bolbs,sw);
		
		
	}

	private static string ToStr(bool[] sw)
	{
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < sw.Length;i++)
		{
			sb.Append((int)(sw[i]?(1):(0)));
		}
		return sb.ToString();
	}
	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

	
}

public class Bolb
{
	public int Index{get;set;}
	public int Connecting{get;set;}
	public List<int> Switches{get;set;}
	public int Amari{get;set;}
	
	public Bolb()
	{
		Switches=new List<int>();
	}
	
	public bool IsLight(bool[] sw)
	{
		int knt=0;
		for(int i = 0; i < Switches.Count;i++)
		{
			if(sw[Switches[i]])knt++;
		}
		
		return (knt%2==Amari);
	}
}

