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


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadIntArray();
            int N = nm[0], M = nm[1];
            var list = new ushort[M];
            for (int i = 0; i < M; i++)
            {
                var ks = ReadIntArray();
                ushort bits = 0;
                foreach (var s in ks.Skip(1).Select(val => val - 1))
                {
                    bits |= (ushort) (1 << s);
                }

                list[i] = bits;
            }

            var p = ReadIntArray();
            for (var i = 0; i < p.Length; i++)
            {
                list[i] |= (ushort) (p[i] << 10);
            }

            int count = 0;
            for (int i = 0; i < 1 << N; i++)
            {
                int mask = (1 << 10) | i;
                for (var r = 0; r < list.Length; r++)
                {
                    var num = mask & list[r];

                    num = ((num & 0xAAAA) >> 1) ^ (num & 0x5555);
                    num = ((num & 0xCCCC) >> 2) ^ (num & 0x3333);
                    num = ((num & 0xf0f0) >> 4) ^ (num & 0x0f0f);
                    num = ((num & 0xff00) >> 8) ^ (num & 0x00ff);

                    if (num == 1) goto end;
                }

                count++;
                end: ;
            }

            Out(count);
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

//    class PriorityQueue<T>
//    {
//        private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
//
//        public PriorityQueue()
//        {
//        }
//
//        public void Push(T item, int priority)
//        {
//            var itemIndex = _list.Count;
//            _list.Add(Tuple.Create(priority, item));
//        }
//
//        public T Pop()
//        {
//        }
//
//        public T Peek()
//        {
//            return _list[0].Item2;
//        }
//
//        private void Swap(int index1, int index2)
//        {
//            var tmp = _list[index1];
//            _list[index1] = _list[index2];
//            _list[index2] = tmp;
//        }
//    }

    class UnionFind
    {
        private readonly int[] _array;

        public UnionFind(int N)
        {
            _array = new int[N];
            for (int i = 0; i < N; i++)
            {
                _array[i] = i;
            }
        }

        public int GetRootNode(int n)
        {
            if (_array[n] == n) return n;
            return _array[n] = GetRootNode(_array[n]);
        }

        public void UnionGroup(int a, int b)
        {
            var rootA = GetRootNode(a);
            var rootB = GetRootNode(b);
            if (rootA == rootB) return;
            _array[rootA] = rootB;
        }

        public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);

        public bool IsRoot(int n) => _array[n] == n;
    }
}

Measured memory_bytes: 13396