import qualified Data.Set as S splitEvery5 :: [String] -> [[String]] splitEvery5 = takeWhile (not . null) . map (take 5) . iterate (drop 5) main :: IO () main = interact $ solve . splitEvery5 . tail . words solve :: [[String]] -> String solve xss = if null (filter (\xs -> "YES" == last xs) xss) then head $ S.toList ((S.fromList $ map show [0..9]) S.\\ noss) else head . S.toList $ yess S.\\ noss where yess = foldr1 S.intersection $ map S.fromList $ map init $ filter (\xs -> "YES" == last xs) xss noss = S.fromList . concat $ map init $ filter (\xs -> "NO" == last xs) xss