n = int(input()) l = [] for _ in range(n): a,b,c,d,e = input().split() a,b,c,d = map(int, [a, b, c, d]) l.append([a, b, c, d, e]) for i in range(10): ok = True for a,b,c,d,e in l: if e == 'NO' and i in (a, b, c, d): ok = False if e == 'YES' and i not in (a, b, c, d): ok = False if ok: print(i) exit(0)