#include <bits/stdc++.h>
using namespace std;
static const int MAX = 2e5 + 6;
int main() {
  string s;
  cin >> s;
  set<string> unique;
  int n = s.length();
  char temp = s[0];
  int cnt = 1;
  int max_cnt = 0;
  for (int i = 1; i < n; i++) {
    if (temp == s[i]) {
      cnt++;
    } else {
      temp = s[i];
      cnt = 1;
    }
    if (cnt > max_cnt) {
      max_cnt = cnt;
    }
  }
  cout << n - max_cnt << endl;
  return 0;
}
