n=input() t=[] for _ in[0]*n: a,b,c,d,x=raw_input().split() if x=="NO": if len(t)==0: t=[`i`for i in range(10)] if a in t:t.remove(a) if b in t:t.remove(b) if c in t:t.remove(c) if d in t:t.remove(d) else: if len(t)==0: t=[a,b,c,d] t=[i for i in[a,b,c,d]if i in t] print t[0]