#include <bits/stdc++.h>
using namespace std;
char s[1000000 + 2];
int main(void) {
  scanf("%s", s);
  int n = strlen(s);
  vector<int> nxt(n + 1), prev(n + 1);
  for (int i = 0; i < n; i++) {
    nxt[i] = i + 1;
    prev[i] = i - 1;
  }
  set<int> del;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      del.insert(i);
      del.insert(i + 1);
    }
  }
  int ans = 0;
  while (!del.empty()) {
    ans++;
    vector<int> q;
    for (int e : del) {
      q.push_back(e);
    }
    del.clear();
    for (int i = 0; i < q.size();) {
      int pr = prev[q[i]];
      int last = q[i++];
      while (i < q.size() && nxt[last] == q[i]) {
        last = q[i++];
      }
      if (pr >= 0) {
        nxt[pr] = nxt[last];
        if (nxt[last] < n && s[nxt[last]] != s[pr]) {
          del.insert(pr);
          del.insert(nxt[last]);
        }
      }
      if (nxt[last] < n) {
        prev[nxt[last]] = pr;
      }
    }
  }
  printf("%i\n", ans);
  return 0;
}
