class Program { static void Main(string[] args) { string inputTurn = Console.ReadLine()!; int turn = int.Parse(inputTurn); List yesList = new List(); List noList = new List(); for (int i = 0; i < turn; i++) { string[] inputNum = Console.ReadLine()!.Split(' '); if (inputNum[4] == "YES") { for (int j = 0; j < 4; j++) { yesList.Add(inputNum[j]); } } else { for (int j = 0; j < 4; j++) { noList.Add(inputNum[j]); } } } yesList.Sort(); List duplicateList = new List(); if (yesList.Count > 5) { for (int i = 1; i < yesList.Count; i++) { if (yesList[i - 1] == yesList[i]) { duplicateList.Add(yesList[i]); } } } else { for (int i = 0; i < yesList.Count; i++) { duplicateList.Add(yesList[i]); } } List notIncluded = new List(); HashSet listSet = new HashSet(noList); for (int i = 0; i <= 9; i++) { if (!listSet.Contains(i.ToString())) { notIncluded.Add(i.ToString()); } } if (noList.Count == 0) { Console.WriteLine(duplicateList[0]); } else if (yesList.Count == 0) { Console.WriteLine(notIncluded[0]); } else { listSet = new HashSet(notIncluded); for (int i = 0; i < duplicateList.Count; i++) { if (listSet.Contains(duplicateList[i])) { Console.WriteLine(duplicateList[i]); break; } } } } }