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

int main()
{
    int k = 'A', cnt = 0;
    string s;

    cin >> s;
    
    for( int i = 0; i < s.size(); i++ )
    {
        if( k >= s[i] )
            cnt++;
        k = s[i];
    }

    cout << cnt << endl;

    return 0;
}
