local str = io.read("*a")
local spos = string.find(str, "A")
local epos

for i=string.len(str),spos + 1, -1 do
	local v = string.sub(str, i, i)
	if v == "Z" then
		epos = i
		break
	end
end

if not epos then
	return 0
end

return epos - spos + 1