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

namespace CSharpSample01
{

    class Program
    {

        static int Find(List<int>[] member_list, List<int> leak_list, bool[] is_bad)
        {
            int ans = -1;

            for(int i = 0; i < leak_list.Count; i++)
            {
                int leaked_num = leak_list[i];

                for(int mem_num = 0; mem_num < is_bad.Count(); mem_num++)
                {
                    if (is_bad[mem_num])
                    {
                        for(int mydata = 0; mydata < member_list[mem_num].Count(); mydata++)
                        {
                            if(member_list[mem_num][mydata] == leaked_num)
                            {
                                break;
                            }
                            if(mydata == member_list[mem_num].Count() - 1)
                            {
                                is_bad[mem_num] = false;
                            }
                        }
                    }
                }


            }

            /*
            for(int i = 0; i < is_bad.Count(); i++)
            {
                Console.WriteLine($"{i} : {is_bad[i]}");
            }
            */

            int cnt_bad = 0;
            int leak_person = 0;

            for(int i = 0; i < is_bad.Count(); i++)
            {
                if (is_bad[i])
                {
                    leak_person = i;
                    cnt_bad++;
                }
            }

            if(cnt_bad >= 2 || cnt_bad == 0)
            {
                ans = -1;
            }
            else
            {
                ans = leak_person + 1;
            }


            return ans;
        }

        static void Main(string[] args)
        {
            while (true)
            {
                int N = int.Parse(Console.ReadLine());

                if(N == 0)
                {
                    break;
                }

                List<int>[] member_list = new List<int>[N];

                //構成員情報を登録
                for(int i = 0; i < N; i++)
                {
                    int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                    member_list[i] = new List<int>();

                    for(int j = 1; j < input.Length; j++)
                    {
                        member_list[i].Add(input[j] - 1);
                    }

                }

                //リーク情報
                int[] leak = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                List<int> leak_list = new List<int>();
                
                for (int j = 1; j < leak.Length; j++)
                {
                    leak_list.Add(leak[j] - 1);
                }

                bool[] is_bad = new bool[N];

                for(int i = 0; i < N; i++)
                {
                    if(member_list[i].Count() > 0)
                    {
                        is_bad[i] = true;
                    }
                    else
                    {
                        is_bad[i] = false;
                    }
                    
                }

                int ans = -1;

                ans = Find(member_list, leak_list, is_bad);


                Console.WriteLine(ans);

            }
            
        }
    }
}


Measured memory_bytes: 22504