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

int main(){
  string s;
  cin >> s;
  string table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int move = 0;
  int out = 0;

  for( int i = 0; i < s.length(); i++ ){
    while(1){
      move++;
      if( table[(move-1)%(table.length())] == 'Z'){
        out++;
      }
      if(table[move%(table.length())] == s[i]) break;
    }
  }
  cout << out << endl;
}