table = [*0..9] gets.to_i.times{ tmp = gets.split.map(&:chomp) if tmp[4] == 'YES' table = table & tmp[0..3].map(&:to_i) else table = table - tmp[0..3].map(&:to_i) end } p table[0]