import Control.Applicative ((<$>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B main :: IO () main = print =<< solve <$> B.getLine solve :: ByteString -> Int solve bs | (B.head bs) /= '1' = -1 | B.length bs == 1 = -1 | otherwise = B.foldl' (\acc -> \x -> if x /= '3' then (-1) else if acc == (-1) then (-1) else acc + 1) 0 $ B.tail bs