#include<iostream>
#include<string>
using namespace std;

int main(){
  string str;
  int cnt = 0;
  cin >> str;
  if(str[str.size()-1] == 'A') {++cnt;}
  for(int i=0; i<str.size()-1; ++i){
    if(str[i] == 'A'){
      ++cnt;
    }else if(str[i] >= str[i+1] && str[i+1] != 'A'){
      ++cnt;
    }
  }
  cout << cnt << endl;
}

