'use strict'

const calc = (arr, str) => {
  for (let i = 0;i < arr.length;i++) {
    if (arr[i] == str) return i;
  }
}

function main(arg) {
  arg = arg.split('');
  let gra = arg.slice();
  gra = gra.reverse();
  const a = calc(arg, 'A');
  const z = gra.length - calc(gra, 'Z');
  const str_length = z - a
  if (str_length > 0) {
    console.log(str_length)
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));