import Control.Monad import qualified Data.Set as S rInt :: String -> Int rInt = read iSet = S.singleton (-1) solve xs yes no | length xs == 0 = head $ S.toList result | last (head xs) == "YES" = solve (tail xs) yes' no | otherwise = solve (tail xs) yes no' where result | yes == iSet = S.difference (S.fromList [0..9]) no | otherwise = S.difference yes no yes' | yes == iSet = xs' | otherwise = S.difference yes (S.difference yes xs') no' | no == iSet = xs' | otherwise = S.union no xs' xs' = S.fromList $ map (rInt) $ init $ head xs main = do n <- readLn xs <- map words <$> replicateM n getLine print $ solve xs iSet iSet