n=int(input()) data=[input().split() for i in range(n)] d=list("0123456789") for i in range(n): if data[i][4]=="NO": for j in range(4): d[int(data[i][j])]="-1" D=[int(s) for s in d] print(max(D))