#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 2;
int a[maxn], nxt[maxn], prv[maxn];
char c[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size(), T = 0;
  int cur = -1;
  for (int i = 0; i < n; i++) {
    if (!i || s[i - 1] != s[i]) {
      if (~cur) nxt[cur] = cur + 1;
      T++;
      cur++;
      c[cur] = s[i];
      prv[cur] = cur - 1;
    }
    a[cur]++;
  }
  nxt[cur] = maxn;
  int ans = 0, first = 0;
  while (T > 1) {
    cur = first;
    int F = first;
    while (cur != maxn) {
      if (cur == F || nxt[cur] == maxn)
        a[cur]--;
      else
        a[cur] = max(a[cur] - 2, 0);
      if (!a[cur]) {
        T--;
        if (prv[cur] == -1) {
          first = nxt[cur];
        } else {
          nxt[prv[cur]] = nxt[cur];
        }
        if (nxt[cur] < maxn) prv[nxt[cur]] = prv[cur];
      }
      cur = nxt[cur];
    }
    cur = first;
    while (cur != maxn) {
      while (nxt[cur] != maxn && c[cur] == c[nxt[cur]]) {
        a[cur] += a[nxt[cur]];
        if (nxt[nxt[cur]] != maxn) prv[nxt[nxt[cur]]] = cur;
        nxt[cur] = nxt[nxt[cur]];
        T--;
      }
      cur = nxt[cur];
    }
    ans++;
  }
  cout << ans;
}
