import Control.Applicative
import Data.Maybe
import Data.List

findLast :: (a->Bool) -> [a] -> Maybe Int
findLast p xs = h p xs 0 Nothing
                where h _ [] _ acc = acc
                      h p (x:xs) ind acc = if p x
                                           then h p xs (ind+1) next
                                           else h p xs (ind+1) acc
                        where next = (Just ind) <|> acc

solve :: String -> Maybe Int
solve s = do x <- findIndex (=='A') s :: Maybe Int
             y <- findLast (=='Z') s :: Maybe Int
             Just (y-x+1) :: Maybe Int

main = do
  s <- getLine
  putStrLn $ show $ fromJust $ solve s
