import Data.Set (Set) import qualified Data.Set as S main :: IO () main = print =<< solve <$> getLine isMow :: String -> Bool isMow cs = ((S.size $ S.fromList cs) == 1) && (head cs == '3') solve :: String -> Int solve s | head s /= '1' = -1 | not $ isMow $ tail s = -1 | otherwise = length $ tail s