(* O(|s|) *)
let string_to_char_array s = Array.init (String.length s) (fun i -> s.[i])

(* O(|s|) *)
let solve s =
  let cs1 = string_to_char_array s |> Array.to_list |> List.mapi (fun i c -> i, c) in
  let cs2 = List.rev cs1 in
  let start = List.find (fun (_, c) -> c = 'A') cs1 |> fst in
  let stop = List.find (fun (_, c) -> c = 'Z') cs2 |> fst in
  stop - start + 1

let _ = read_line () |> solve |> string_of_int |> print_endline