#!/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) for _ in xrange(N): nums, yes = func(*raw_input().split()) if yes: ok &= set(nums) else: ok -= set(nums) print list(ok)[0]