import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	}
} import java.util.*; util.* java import java.util.stream.Collectors; Collectors java.util.stream public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s = sc.next(); s sc.next() sc.next sc int indexOfA = s.indexOf('A'); indexOfA s.indexOf('A') s.indexOf s 'A' int indexOfZ = s.lastIndexOf('Z'); indexOfZ s.lastIndexOf('Z') s.lastIndexOf s 'Z' String subst = s.substring(indexOfA, indexOfZ+1); subst s.substring(indexOfA, indexOfZ+1) s.substring s indexOfA indexOfZ+1 indexOfZ 1 int ans = subst.length(); ans subst.length() subst.length subst System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	}
} Main
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int indexOfA = s.indexOf('A');
		int indexOfZ = s.lastIndexOf('Z');
		String subst = s.substring(indexOfA, indexOfZ+1);
		int ans = subst.length();
		System.out.println(ans);
		sc.close();
	}
}