#include <bits/stdc++.h>
using namespace std;
bool chk[1000002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, cnt = 0, first = 1;
  string s;
  vector<int> Next, Prev;
  cin >> s;
  N = s.size();
  s = s[0] + s + s[s.size() - 1];
  Prev.resize(s.size());
  Next.resize(s.size());
  Next[0] = 1;
  Prev[N + 1] = N;
  for (int i = 1; i <= N; i++) {
    Next[i] = i + 1;
    Prev[i] = i - 1;
  }
  for (;; cnt++) {
    bool change = false;
    for (int i = first; i <= N; i = Next[i]) {
      if (s[Prev[i]] != s[i] || s[i] != s[Next[i]]) {
        chk[i] = true;
        change = true;
      }
    }
    if (!change) break;
    for (int i = first; i <= N; i = Next[i]) {
      if (chk[i]) {
        if (i == first) first = Next[i];
        Prev[Next[i]] = Prev[i];
        Next[Prev[i]] = Next[i];
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}
