find :: (Ord a) => Int -> a -> [a] -> Int
find _ _ [] = (-1)
find i c (x:xs)
  | c == x = i
  | otherwise = find (i+1) c xs

fstFind :: (Ord a) => a -> [a] -> Int
fstFind c = find 0 c

main = do
  line <- getLine
  let
    len = length line
    idxA = fstFind 'A' line
    idxZ = fstFind 'Z' $ reverse line
    ans = len - idxZ - idxA
  putStrLn $ show ans
