#!/usr/bin/python func = lambda a, b, c, d, r: [map(int, (a, b, c, d))] + [r=='YES'] N = int(raw_input()) al = range(10) ok = set(al) ng = set() for _ in xrange(N): nums, yes = func(*raw_input().split()) if yes: ok &= set(nums) else: ng |= set(nums) ok &= set(al) - ng print list(ok)[0]