n = int(input()) yes = [] no = [] ans = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) for _ in range(n): a, b, c, d, r = input().split() l = [a, b, c, d] if r == 'NO': for i in l: no.append(i) else: yes.append(l) for i in yes: ans = ans & set(i) ans = list(ans) no = list(set(no)) if len(ans) == 1: print(ans[0]) exit() else: for j in no: if j in ans: ans.remove(j) print(ans[0])