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