#include <bits/stdc++.h>
using namespace std;
int ans, mx;
string s;
map<string, int> x;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int j = i;
    string now = "";
    while (j < s.size() && s[j] == s[i]) j++, now += s[j - 1];
    x[now]++;
    i = j - 1;
  }
  for (map<string, int>::iterator it = x.begin(); it != x.end(); it++)
    mx = max(it->second, mx);
  cout << s.size() - (mx == 1 ? 0 : mx) << endl;
  return 0;
}
