#include <bits/stdc++.h>
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 1100000;
const long double pi = atan(1) * 4;
const long long md = (1e9) + 7;
const long long mx = (1e18);
long long n, m, k, l, w, j, i, res, kol, s[N], c[N], cvet[N], pr[N], ne[N], x,
    xx;
string ss;
int main() {
  ios_base ::sync_with_stdio(0);
  getline(cin, ss);
  ss = "." + ss;
  l = 1;
  k = 1;
  for (i = 2; i < ss.size(); i++)
    if (ss[i] == ss[l])
      k++;
    else {
      kol++;
      s[kol] = l;
      c[kol] = k;
      cvet[kol] = ss[l];
      k = 1;
      l = i;
    }
  kol++;
  s[kol] = l;
  c[kol] = k;
  cvet[kol] = ss[l];
  for (i = 1; i <= kol; i++) {
    ne[i] = i + 1;
    pr[i] = i - 1;
  }
  ne[kol] = 0;
  pr[1] = 0;
  x = 0;
  ne[x] = 1;
  c[0] = mx;
  while (1) {
    if (ne[ne[0]] == 0) break;
    res++;
    x = 0;
    while (1) {
      if (pr[x]) c[x]--;
      if (ne[x]) c[x]--;
      x = ne[x];
      if (x == 0) break;
    }
    x = 0;
    while (1) {
      if (c[x] <= 0) {
        ne[pr[x]] = ne[x];
        pr[ne[x]] = pr[x];
      }
      x = ne[x];
      if (x == 0) break;
    }
    x = 0;
    while (1) {
      if (cvet[x] == cvet[ne[x]]) {
        c[ne[x]] += c[x];
        ne[pr[x]] = ne[x];
        pr[ne[x]] = pr[x];
      }
      x = ne[x];
      if (x == 0) break;
    }
  }
  cout << res;
}
