N = int(input()) nums = ["0","1","2","3","4","5","6","7","8","9"] for i in range(N): l = list(input().split()) if l[-1] == "YES": for item in l: if item in nums: nums.append(item) else: for j in l: if j in nums: nums.remove(j) print(int(nums[0]))