#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  string s;
  cin >> s;
  int c=0;
  for(;;){
    string ss(s);
    sort(ss.begin(), ss.end());
    if(ss == s)
      break;
    for(int i=0; i < s.length(); i++){
      if(s[i] > s[i+1]){
	char tmp = s[i+1];
	s[i+1] = s[i];
	s[i] = tmp;
	break;
      }
    }
    c++;
  }
  cout << c << endl;
  return 0;
}