#include <bits/stdc++.h>
using namespace std;
string s;
int ans = 0;
int L[1234567];
int R[1234567];
int dist[1234567];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int n = s.size();
  set<int> foo;
  for (int i = 0; i < n; i++) {
    L[i] = i - 1;
    R[i] = i + 1;
    if (i + 1 < n && s[i] != s[i + 1]) foo.insert(i);
    if (i - 1 > -1 && s[i] != s[i - 1]) foo.insert(i);
  }
  memset(dist, 0, sizeof dist);
  bool f;
  while (foo.size()) {
    ans++;
    f = 1;
    vector<int> tmp;
    for (int I : foo)
      if (dist[I] == 0) tmp.push_back(I);
    foo.clear();
    for (int I : tmp) {
      int LL = L[I];
      int RR = R[I];
      if (LL == -1 && RR == n) continue;
      f = 0;
      dist[I] = 1;
      if (LL == -1) {
        L[RR] = -1;
        continue;
      }
      if (RR == n) {
        R[LL] = n;
        continue;
      }
      if (foo.count(LL) == 0 && s[LL] != s[RR])
        foo.insert(LL);
      else if (foo.count(LL) == 1 && s[LL] == s[RR] && L[LL] == -1)
        foo.erase(LL);
      else if (foo.count(LL) == 1 && s[LL] == s[RR] && L[LL] != -1 &&
               s[L[LL]] == s[LL])
        foo.erase(LL);
      if (R[RR] != n) {
        if (s[R[RR]] != s[RR])
          foo.insert(RR);
        else if (s[LL] != s[RR]) {
          foo.insert(LL);
          foo.insert(RR);
        } else if (foo.count(RR))
          foo.erase(RR);
      } else {
        if (s[LL] != s[RR])
          foo.insert(RR);
        else if (foo.count(RR))
          foo.erase(RR);
      }
      R[LL] = RR;
      L[RR] = LL;
    }
  }
  cout << max(0, ans - f) << '\n';
  return 0;
}
