using System.Collections.Generic;
using System;

class Question_prop { // ????????????????????¶??????????????????????????¨???????????????
	public const int DAY_MAX    = 30;
	public const int YAOMAN_MAX = 50;
	public const int NO_ANSWER  = -1; // ??????????????¨?????§?????????
};

class YaoMan { //Yah-Man ??§????????????????°??????????
	private List<int> m_vacantDays; // ????????\
	private ulong m_mapId; // ?????????????????????????????°????????????ID
	private ulong[] m_gatheringProgressAtDay; // ???????????\????????????????????°????????????(???????????¨???)
	public bool isFree(int day) { // day?????????
		return m_vacantDays.Contains(day);
	}
	
	public void setVacantDay(int day) { // ????????\?????????
		m_vacantDays.Add(day);
	}

	public ulong mapId {
		get {
			return m_mapId;
		}
	}
	
	public ulong getGatheringProgressAtDay(int day) { // ??????????????????????????£??????????????§??????????????????????????????
		return m_gatheringProgressAtDay[day];
	}
	public void setGatheringProgressAtDay(int day, ulong mapId) {
		m_gatheringProgressAtDay[day] = mapId;
	}
	
	public YaoMan(int id) {
		m_gatheringProgressAtDay = new ulong[Question_prop.DAY_MAX + 1];
		m_mapId = (ulong)1 << id;
		m_gatheringProgressAtDay[0] = mapId; // ???????????°???????????????????????£?????????
		m_vacantDays = new List<int>();
	}
};

class GatheringTheMaps{
	public static void Main()
	{
		for(int memberNum = int.Parse(Console.ReadLine());memberNum != 0;memberNum = int.Parse(Console.ReadLine())) {
			YaoMan[] yaoFamily = new YaoMan[memberNum];
			inputProcedure(yaoFamily); // ???????????????????????????????????¨????????\??????
			calcGatheringInfoProcedure(yaoFamily); // ?????????n??\?????§????????????????????°???????????±??????????????????
			
			echoAnswerProcedure(yaoFamily); // ???????????????
		}
	}
	
	public static void inputProcedure(YaoMan[] yaoFamily) {
		for (int i = 0; i < yaoFamily.Length; ++i) {
			yaoFamily[i] = new YaoMan(i);
			
			string[] inputStr = Console.ReadLine().Split(' ');
			bool isFirstInput = true; // ??\?????????????????????????????????(????????\?????\??°)
			foreach (string tmp in inputStr) {
				if (isFirstInput) {
					isFirstInput = false;
					continue;
				}
				yaoFamily[i].setVacantDay(int.Parse(tmp)); // ????????\?????????
			}
		}
	}
	
	public static void calcGatheringInfoProcedure(YaoMan[] yaoFamily) {
		for (int day = 1; day <= Question_prop.DAY_MAX; ++day) {
			ulong supplyMapId = 0; // days????????????????????°????????????(???????????¨???)
			for (int i = 0; i < yaoFamily.Length; ++i) { // day????????????????????°?????????????????????
				ulong alreadyGatheredMap = yaoFamily[i].getGatheringProgressAtDay(day - 1); // ?????\?????§???i??????????????????????????°???

				if (yaoFamily[i].isFree(day)) { // day??§????????????????????????????????°?????????????????????
					supplyMapId |= alreadyGatheredMap;
				}
			}
			
			for (int i = 0; i < yaoFamily.Length; ++i) { // day??????????????????????????°?????????????????????
				ulong alreadyGottenMap = yaoFamily[i].getGatheringProgressAtDay(day - 1); // 
				yaoFamily[i].setGatheringProgressAtDay(day, alreadyGottenMap); // ?????????????????\????????§????????????????????¬??\???????????????
				if (yaoFamily[i].isFree(day)) { // ???????????????????????????????????????????????\?????????????????°???????????????????????¨?????§??????
					yaoFamily[i].setGatheringProgressAtDay(day, supplyMapId);
				}
			}
		}
	}
	
	public static void echoAnswerProcedure(YaoMan[] yaoFamily) {
		ulong allMap = ((ulong)1 << yaoFamily.Length) - 1; // ??¨???????????????????????????????????£?????¶???
		//Console.WriteLine("all: {0, -16:X}", allMap);
		for (int day = 1; day <= Question_prop.DAY_MAX; ++day) {
			for (int i = 0; i < yaoFamily.Length; ++i) {
				//Console.WriteLine("{0}_{1}: {2, -16:X}",i, day, yaoFamily[i].getGatheringProgressAtDay(day));
				if (yaoFamily[i].getGatheringProgressAtDay(day) == allMap) { // i???day?????¨??????????????????????????¨?????§??????
					Console.WriteLine("{0}", day);
					return;
				}
			}
		}
		Console.WriteLine("{0}", Question_prop.NO_ANSWER);
	}
};

Measured memory_bytes: 10128