#include <bits/stdc++.h>
using std::sort;
int n;
int cnt[1000006];
int f[1000006];
char d[1000006];
int idx;
void upd(int n) {
  if (cnt[n] > 0) {
    if (idx > 0 && d[n] == d[idx - 1]) {
      cnt[idx - 1] += cnt[n];
      return;
    }
    cnt[idx] = cnt[n];
    d[idx] = d[n];
    idx++;
  }
}
int main() {
  char ch, last = '\0';
  for (n = 0; ~scanf("%c", &ch);) {
    if (ch == '\n') break;
    if (last == '\0') {
      last = ch;
      d[n] = ch;
      cnt[n]++;
      continue;
    }
    if (ch == last)
      cnt[n]++;
    else {
      cnt[++n] = 1;
      last = ch;
      d[n] = ch;
    }
  }
  ++n;
  if (n == 1) {
    printf("0");
    return 0;
  }
  int ans = 0, flag = 1;
  for (; flag;) {
    ++ans;
    idx = 0;
    cnt[0]--;
    upd(0);
    for (int i = 1; i < n - 1; ++i) {
      cnt[i] -= 2;
      upd(i);
    }
    cnt[n - 1]--;
    upd(n - 1);
    n = idx;
    if (n <= 1) break;
  }
  printf("%d", ans);
}
