b = [] c = (0..9).to_a for i in 1..gets.chomp.to_i w = gets.chomp.split n = w.slice(0..3).map &:to_i if w[-1] == "YES" then c &= n else b |= n; c -= n end end puts c[0]