n = gets.to_i ans = [0,1,2,3,4,5,6,7,8,9].map(&:to_s) n.times do a,b,c,d,r = gets.split if r == 'NO' ans -= [a,b,c,d] else ans = a, b, c, d end end puts ans.first