#include <bits/stdc++.h>
using namespace std;
char a[1000001], b[1000001];
long long n, ans, c, s[1000001], m;
signed main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (long long i = 1; i <= n; ++i)
    if (a[i] == b[m]) {
      ++s[m];
    } else {
      b[++m] = a[i];
      s[m] = 1;
    }
  while (m > 1) {
    c = 0;
    for (long long i = 1; i <= m; ++i)
      if (i == 1 || i == m) {
        --s[i];
      } else {
        --s[i];
        --s[i];
      }
    for (long long i = 1; i <= m; ++i) {
      if (s[i] < 1) continue;
      if (b[i] == b[c]) {
        s[c] += s[i];
      } else {
        b[++c] = b[i];
        s[c] = s[i];
      }
    }
    ++ans;
    m = c;
  }
  printf("%lld", ans);
  return 0;
}
