#include <bits/stdc++.h>
using namespace std;
string s;
int dist[1234567], ans = 0;
int L[1234567];
int R[1234567];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int n = s.size();
  set<int> foo, bar;
  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);
  while (foo.size()) {
    ans++;
    bar.clear();
    for (int I : foo) {
      if (dist[I]) continue;
      dist[I] = 1;
      int LL = L[I];
      int RR = R[I];
      if (LL == -1) {
        L[RR] = -1;
        continue;
      }
      if (RR == n) {
        R[LL] = n;
        continue;
      }
      if (L[LL] != -1) {
        if (s[L[LL]] != s[LL])
          bar.insert(LL);
        else if (s[LL] != s[RR])
          bar.insert(LL);
        else if (bar.count(LL))
          bar.erase(LL);
      } else {
        if (s[LL] != s[RR])
          bar.insert(LL);
        else if (bar.count(LL))
          bar.erase(LL);
      }
      if (R[RR] != n) {
        if (s[R[RR]] != s[RR])
          bar.insert(RR);
        else if (s[LL] != s[RR])
          bar.insert(RR);
        else if (bar.count(RR))
          bar.erase(RR);
      } else {
        if (s[LL] != s[RR])
          bar.insert(RR);
        else if (bar.count(RR))
          bar.erase(RR);
      }
      R[LL] = RR;
      L[RR] = LL;
    }
    foo = bar;
  }
  cout << ans << '\n';
  return 0;
}
