import Control.Applicative import Control.Monad import Data.List parse :: [String] -> [Int] parse ds = let (ns, p) = splitAt 4 ds in (if head p=="NO" then ([0..9]\\) else id) $ map read ns main = readLn >>= flip replicateM (words <$> getLine) >>= print . head . foldl intersect [0..9] . map parse