import Control.Monad (replicateM) -- [Char]あるいは String を Int にする toInt :: (String -> Int) toInt x = read x :: Int disammble :: [String] -> ([Int], String) disammble s = (map toInt (init s), last s) judge :: Eq a => [a] -> ([a], String) -> [a] judge cand phrase = if snd phrase == "NO" then [x | x <- cand, x `notElem` fst phrase] else [x | x <- fst phrase, x `elem` cand] main :: IO () main = do n <- readLn input <- replicateM n getLine let mind = map words input let res = foldl judge [0 .. 9] (map disammble mind) print $ head res