#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n;i++)
int main(){
    string s; cin>>s;
    char now;
    int ans=0;
    rep(i,s.size()){
        if(!i){if(s[i]=='A')ans++;now=s[0];continue;}
        else if(now==s[i]){ans++; now=s[i];continue;}
        if(now>s[i])ans++;
        now=s[i];
    }
    cout<<ans<<endl;
}