import Data.List (elemIndices)

maxLength :: String -> Int
maxLength s = z - a + 1
    where
        a = head $ elemIndices 'A' s
        z = last $ elemIndices 'Z' s

main :: IO ()
main = print . maxLength =<< getLine
