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 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 == (int)Math.Pow(2, lightCount) - 1)
                {
                    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]
                    });
                }
            }
        }
    }
}
