import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S = sc.next(); S sc.next() sc.next sc int firstIndex = S.length(); firstIndex S.length() S.length S int lastIndex = S.length(); lastIndex S.length() S.length S char[] sArray = S.toCharArray(); sArray S.toCharArray() S.toCharArray S for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		} int i = 0; int i = 0; i 0 i < sArray.length i sArray.length sArray sArray.length i++ i++ i {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		} {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		} if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i; firstIndex == S.length() && sArray[i] == 'A' firstIndex == S.length() firstIndex S.length() S.length S sArray[i] == 'A' sArray[i] sArray i 'A' firstIndex = i firstIndex i if (sArray[i] == 'Z')
				lastIndex = i; sArray[i] == 'Z' sArray[i] sArray i 'Z' lastIndex = i lastIndex i System.out.println(S.substring(firstIndex, lastIndex + 1).length()) System.out.println System.out System System.out S.substring(firstIndex, lastIndex + 1).length() S.substring(firstIndex, lastIndex + 1).length S.substring(firstIndex, lastIndex + 1) S.substring S firstIndex lastIndex + 1 lastIndex 1 sc.close() sc.close sc String[] args args public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
} public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
} Main
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
}