N = int(input()) li = [0]*10 for _ in range(N): a,b,c,d,r = map(str,input().split()) S = {int(a),int(b),int(c),int(d)} if r[0] == "Y": for i in range(10): if i not in S: li[i] = -1 else: for i in S: li[i] = -1 for i in range(10): if li[i] == 1: print(i) exit()