import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String s = scan.next(); s scan.next() scan.next scan int a = s.indexOf("A"); a s.indexOf("A") s.indexOf s "A" int z = s.lastIndexOf("Z"); z s.lastIndexOf("Z") s.lastIndexOf s "Z" String r = s.substring(a, z+1); r s.substring(a, z+1) s.substring s a z+1 z 1 int ans = r.length(); ans r.length() r.length r System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		String r = s.substring(a, z+1);
		int ans = r.length();
		System.out.println(ans);
	}
}
