N = int(input()) inlist = [] for i in range(N): inlist.append(input().split()) ans_yes_list = [] ans_no_list = [] for _ in inlist: if _[4] == "YES": for n in range(4): ans_yes_list.append(_[n]) if _[4] == "NO": for n in range(4): ans_no_list.append(_[n]) s = set() uq_ans_yes_list = list(set([x for x in ans_yes_list if x in s or s.add(x)])) uq_ans_no_list = [] for _ in ans_no_list: if _ not in uq_ans_no_list: uq_ans_no_list.append(_) if len(uq_ans_no_list) == 9: temp = [str(i) for i in range(10)] for _ in uq_ans_no_list: temp.remove(str(_)) print(int(temp[0])) else: for _ in uq_ans_yes_list: if _ in uq_ans_no_list: uq_ans_yes_list.remove(str(_)) print(int(uq_ans_yes_list[0]))