import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	} main {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S = sc.next(); S sc.next() sc.next sc int fIndex = S.indexOf("A"); fIndex S.indexOf("A") S.indexOf S "A" int lIndex = S.lastIndexOf("Z"); lIndex S.lastIndexOf("Z") S.lastIndexOf S "Z" System.out.println(S.substring(fIndex, lIndex + 1).length()) System.out.println System.out System System.out S.substring(fIndex, lIndex + 1).length() S.substring(fIndex, lIndex + 1).length S.substring(fIndex, lIndex + 1) S.substring S fIndex lIndex + 1 lIndex 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
}