#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ctr[26] = {};
  int streak = 1;
  for (int i = 1; i < (int)s.size(); ++i) {
    if (s[i] != s[i - 1]) {
      ctr[(int)s[i - 1] - 'a'] = max(streak, ctr[(int)s[i - 1] - 'a']);
      streak = 1;
    } else
      streak++;
  }
  ctr[(int)s[(int)s.size() - 1] - 'a'] =
      max(streak, ctr[(int)s[(int)s.size() - 1] - 'a']);
  sort(ctr, ctr + 26);
  cout << (int)s.size() - ctr[25] << endl;
}
