#include <iostream>

using namespace std;

int main()
{
  string S;
  cin >> S;
  int count = 0;
  int mass = 0;
  for(auto s: S){
    int next = s - 'A';
    if(next <= mass){
      count++;
    }
    mass = next;
  }
  cout << count << endl;
  return 0;
}