#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
using namespace std;
int inf = 1000000000;

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){

  string s;
  cin >> s;
  int cnt = 0;
  int tmp = 0;
  for(int i=0; i<s.size(); i++){
    if( tmp >= s[i]-'A' ){
      cnt++;
    }
    tmp = s[i]-'A';
  }
  cout << cnt << endl;

  return 0;
}