#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
int mod = 1e9 + 7;
int n, m, i, j, k, o;
struct it {
  int nm;
  char ch;
  it() { nm = ch = 0; }
  it(int N, char C) {
    nm = N;
    ch = C;
  }
} s[1000005], t[1000005];
char ss[1000005];
int cnt1, cnt2;
int main() {
  scanf("%s", ss + 1);
  n = strlen(ss + 1);
  cnt1 = cnt2 = 0;
  s[++cnt1].nm = 1;
  s[cnt1].ch = ss[1];
  for (int i = 2; i <= n; i++) {
    if (ss[i] == ss[i - 1])
      s[cnt1].nm++;
    else {
      s[++cnt1].nm = 1;
      s[cnt1].ch = ss[i];
    }
  }
  int ans = 0;
  while (cnt1 > 1) {
    ans++;
    for (int i = 2; i < cnt1; i++) {
      s[i].nm -= 2;
    }
    s[1].nm--;
    s[cnt1].nm--;
    cnt2 = 0;
    for (int i = 1; i <= cnt1; i++) {
      if (s[i].nm > 0) {
        t[++cnt2] = s[i];
      }
    }
    cnt1 = 1;
    s[1] = t[1];
    for (int i = 2; i <= cnt2; i++) {
      if (t[i].ch == t[i - 1].ch) {
        s[cnt1].nm += t[i].nm;
      } else {
        s[++cnt1] = t[i];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
