#include<iostream>
#include<string>
using namespace std;
int p;
int cnt;
void calc(char t){
  if ( p == 25 ) cnt++;
  p = (p+1)%26;

  while(1){
    if ( p == (t-'A') ) break;
    if ( p == 25 ) cnt++;
    p = (p+1)%26;
  }
}

int main(){
  string s;
  cin >> s;
  p = 0;
  cnt = 0;
  for ( int i = 0; i < s.size(); i++ ) calc(s[i]);
  cout << cnt << endl;
}