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