#include <bits/stdc++.h>
using namespace std;
int L[1000006];
int R[1000006];
bool erased[1000006];
int sz = 0;
int V[1000006 * 2];
int sz2 = 0;
int nextt[1000006 * 2];
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    L[i] = i - 1;
    R[i] = i + 1;
    if (i and s[i - 1] != s[i])
      V[sz++] = i;
    else if (i + 1 < s.size() and s[i + 1] != s[i])
      V[sz++] = i;
  }
  R[s.size() - 1] = -1;
  int steps = 0;
  for (; sz; ++steps) {
    sz2 = 0;
    for (int i = 0; i < sz;) {
      int j = i;
      int li = L[V[j]];
      int LL = li;
      while (j < sz and li == L[V[j]]) {
        li = V[j++];
      }
      int RR = R[V[j - 1]];
      if (LL != -1) R[LL] = RR;
      if (RR != -1) L[RR] = LL;
      if (LL != -1) {
        nextt[sz2++] = LL;
      }
      if (RR != -1) {
        nextt[sz2++] = RR;
      }
      i = j;
    }
    sz2 = unique(nextt, nextt + sz2) - nextt;
    sz = 0;
    for (int j = 0; j < sz2; ++j) {
      int i = nextt[j];
      if (L[i] != -1 and s[L[i]] != s[i])
        V[sz++] = i;
      else if (R[i] != -1 and s[R[i]] != s[i])
        V[sz++] = i;
    }
  }
  cout << steps << endl;
  return 0;
}
