#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 100;
struct Node {
  int l, r;
  char ch;
};
char str[maxn];
Node sta[maxn];
int main() {
  ios::sync_with_stdio(false);
  while (scanf("%s", str) != EOF) {
    int top = 0;
    sta[top].l = 0;
    sta[top].ch = str[0];
    for (int i = 1; str[i]; ++i) {
      if (str[i] != str[i - 1]) {
        sta[top++].r = i - 1;
        sta[top].l = i;
        sta[top].ch = str[i];
      }
    }
    sta[top++].r = strlen(str) - 1;
    int ans = 0;
    while (top > 1) {
      --sta[0].r;
      ++sta[top - 1].l;
      for (int i = 1; i < top - 1; ++i) {
        ++sta[i].l;
        --sta[i].r;
      }
      int toptmp = 0;
      for (int i = 0; i < top; ++i) {
        if (sta[i].r >= sta[i].l) {
          sta[toptmp++] = sta[i];
        }
      }
      top = toptmp;
      toptmp = 0;
      for (int i = 1; i < top; ++i) {
        if (sta[i].ch == sta[toptmp].ch) {
          sta[toptmp].r += sta[i].r - sta[i].l + 1;
        } else {
          ++toptmp;
          sta[toptmp] = sta[i];
        }
      }
      top = toptmp + 1;
      ++ans;
    }
    printf("%d\n", ans);
  }
  return 0;
}
