n=int(input()) data=[input().split() for i in range(n)] d=[int(s) for s in list("0123456789")] d_2=[] for i in range(n): if data[i][4]=="NO": for j in range(4): d[int(data[i][j])]=-1 else: for j in range(4): d_2.append(int(data[i][j])) d_3=[] for i in range(10): if d[i]>=0: d_3.append(d[i]) if len(d_3)==1: print(d_3[0]) else: for i in range(len(d_3)): if d_3[i] in d_2: print(d_3[i]) break