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

namespace Switches
{
    class MainClass
    {
        public static void Main()
        {
            var inputs = Console.ReadLine().Split(' ');

            var switchCount = int.Parse(inputs[0]);
            var lightCount = int.Parse(inputs[1]);


            var lights = new int[lightCount, switchCount];
            for (int i = 0; i < lightCount; i++)
            {
                var args = Console.ReadLine().Split(' ').ToList();
                args.RemoveAt(0);
                for (int j = 0; j < args.Count; j++)
                {
                    var n = int.Parse(args[j]);
                    lights[i, n - 1] = 1;
                }
            }

            var lightConditions = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var str = "";
            for (int i = 0; i < lightConditions.Length; i++)
            {
                str = str + lightConditions[i];
            }
            var lightCondition = Convert.ToInt32(str, 2);

            var signalPaterns = Enumerable.Repeat<int>(0, switchCount).ToArray();
            for (int i = 0; i < switchCount; i++)
            {
                var s = "";
                for (int j = 0; j < lightCount; j++)
                {
                    s = s + lights[j, i].ToString();
                }
                signalPaterns[i] = Convert.ToInt32(s, 2);
            }

            var switchPatern = new List<SwitchHolder>();
            for (int i = int.Parse(Math.Pow(2, switchCount).ToString()) - 1; i >= 0; i--)
            {
                switchPatern.Add(new SwitchHolder(i, switchCount, signalPaterns));
            }

            var result = 0;
            for (int i = 0; i < switchPatern.Count; i++)
            {
                var lightState = 0;
                foreach (var item in switchPatern[i].Switches)
                {
                    if (item.isON)
                    {
                        lightState = lightState ^ item.Signal;
                    }
                }
                if (lightState == lightCondition)
                {
                    result++;
                }
            }
            
            Console.WriteLine(result);
        }

        class Switch
        {
            public int ID { get; set; }
            public bool isON { get; set; }
            public int Signal { get; set; }
        }

        class SwitchHolder
        {
            public List<Switch> Switches { get; set; } = new List<Switch>();

            public SwitchHolder(int a, int digits, int[] signalpaterns)
            {
                var bitStr = Convert.ToString(a, 2).PadLeft(digits, '0').ToCharArray();
                for (int i = 0; i < bitStr.Length; i++)
                {
                    var b = false;
                    if (bitStr[i] == '1')
                    {
                        b = true;
                    }
                    Switches.Add(new Switch
                    {
                        ID = i + 1,
                        isON = b,
                        Signal = signalpaterns[i]
                    });
                }
            }
        }
    }
}


Measured memory_bytes: 13504