static void  createEdge(node a, node b)
        {
            edges fwd   = new edges(a.key, b.key, 0, 1);
            edges bckwd = new edges(b.key, a.key, 1, 1);

            a.neighbours.Add(b.key, fwd);
            b.neighbours.Add(a.key, bckwd);
        }
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int      len   = int.Parse(input[0]);

            node[] rcities = new node[len * 2 + 2];

            for (int i = 1; i <= len; i++)
            {
                rcities[i]      = new node();
                rcities[i].key  = i;
                rcities[i].keys = new int[int.Parse(input[1])];
                string[] key = Console.ReadLine().Split();
                for (int j = 0; j < int.Parse(input[1]); j++)
                {
                    rcities[i].keys[j] = int.Parse(key[j]);
                }

                rcities[i + len]      = new node();
                rcities[i + len].key  = i + len;
                rcities[i + len].keys = new int[int.Parse(input[1])];
                for (int j = 0; j < int.Parse(input[1]); j++)
                {
                    rcities[i + len].keys[j] = int.Parse(key[j]);
                }
            }

            createGraph(rcities, int.Parse(input[0]), int.Parse(input[1]));

            //add start edge
            rcities[0] = new node();

            rcities[len * 2 + 2 - 1]     = new node();
            rcities[len * 2 + 2 - 1].key = len * 2 + 2 - 1;
            for (int i = 0; i < int.Parse(input[0]); i++)
            {
                edges fwd    = new edges(0, i + 1, 1, 1);
                edges backwd = new edges(i + 1, 0, 0, 1);
                rcities[0].neighbours.Add(i + 1, fwd);
                rcities[i + 1].neighbours.Add(0, backwd);
            }
            //add backward node edge
            for (int i = int.Parse(input[0]) + 1; i < (2 * len + 2) - 1; i++)
            {
                edges fwd    = new edges(i, (2 * len + 2) - 1, 1, 1);
                edges backwd = new edges((2 * len + 2) - 1, i, 0, 1);
                rcities[i].neighbours.Add((2 * len + 2) - 1, fwd);
                rcities[(2 * len + 2) - 1].neighbours.Add(i, backwd);
            }

            int flow = calcFlow(rcities, len * 2 + 2);

            Console.Write(int.Parse(input[0]) - flow);
            Console.Read();
        }