#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int a[maxn];
int b[maxn];
char s[maxn];
int main() {
  while (~scanf("%s", s)) {
    int n = strlen(s);
    int num = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0 || s[i] != s[i - 1]) a[++num] = i;
      if (i == n - 1 || s[i] != s[i + 1]) a[++num] = i;
    }
    if (num == 2) {
      printf("0\n");
    } else {
      int ans = 0;
      while (num != 2 && num != 0) {
        int head = 1, tail = 1;
        int k = 0;
        while (k < num - 1) {
          int x = a[++k];
          if (k != 1) x++;
          int y = a[++k];
          if (k != num) y--;
          if (x <= y) {
            b[tail++] = x;
            b[tail++] = y;
          } else {
            if (head < tail && k < num && s[b[tail - 1]] == s[a[k + 1]]) {
              int tx = a[++k];
              int ty = a[++k];
              if (k != num) ty--;
              tail--;
              b[tail++] = ty;
            }
          }
        }
        num = 0;
        while (head < tail) a[++num] = b[head++];
        ans++;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
