n = int(input()) turn_list = [] nums_dict = {} meta_turn_list = [] for h in range(0, 10): nums_dict[h] = 0 for i in range(1, n + 1): turn_list = input().split(" ") if turn_list[4] == "NO": meta_turn_list.append(turn_list) elif turn_list[4] == "YES": meta_turn_list.insert(0, turn_list) for turn_list in meta_turn_list: *nums, ans = turn_list nums = [int(x) for x in nums] if ans == "YES": for j in nums: if j in nums_dict: if nums_dict[j] == "potential": nums_dict[j] = "high-potential" else: nums_dict[j] = "potential" elif ans == "NO": for j in nums: nums_dict[j] = "non-potential" for k in nums_dict: if nums_dict[k] == "high-potential": output = k break if "output" not in locals(): for l in range(0, 10): if nums_dict[l] == 0: output = l break #print(meta_turn_list) #print(nums_dict) print(output)