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