n = int(input()) lst = [1 for _ in range(10)] for _ in range(n): a, b, c, d, r = input().split() if r == "YES": for i in range(1, 11): if str(i) not in [a, b, c, d]: lst[i - 1] = 0 else: for i in [a, b, c, d]: lst[int(i) - 1] = 0 print(lst.index(1) + 1)