#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int c[s.length() + 1];
  int segments[s.length() + 1];
  int counter = 0;
  c[0] = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] - 'a' == c[counter])
      segments[counter]++;
    else {
      counter++;
      c[counter] = s[i] - 'a';
      segments[counter] = 1;
    }
  }
  int answer = 0;
  while (counter > 1) {
    answer++;
    segments[1]--;
    segments[counter]--;
    for (int i = 2; i < counter; i++) segments[i] -= min(segments[i], 2);
    int current = 0;
    for (int i = 1; i <= counter; i++) {
      if (segments[i] == 0) continue;
      if (c[i] == c[current]) {
        segments[current] += segments[i];
      } else {
        current++;
        c[current] = c[i];
        segments[current] = segments[i];
      }
    }
    counter = current;
  }
  cout << answer << endl;
}
