N = gets.to_i x = [0,1,2,3,4,5,6,7,8,9] N.times do |i| a = gets.split b = a[0..3].map(&:to_i) if a[4] == "NO" x -= b else x = x & b end if x.size == 1 puts x exit end end