import qualified Data.ByteString.Char8 as BS
f s
 |BS.null s=False
 |BS.head s=='A'&&BS.last s=='Z'=True
 |otherwise=False
main=do
 s<-BS.getLine
 let l=BS.length s
 print$maximum$map BS.length$filter(f)[BS.drop y(BS.take x s)|x<-[0..l],y<-[0..l],y<x]