#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
template <class T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
const int maxn = 1e6 + 10;
struct pnt {
  int pre, nxt, len, num;
} a[maxn];
int n, cnt;
char s[maxn];
int del(int x) {
  int pre = a[x].pre, nxt = a[x].nxt;
  a[pre].nxt = nxt;
  a[nxt].pre = pre;
  return nxt;
}
void print() {
  for (int i = a[0].nxt; i < cnt; i = a[i].nxt) {
    for (int j = 0; j < a[i].len; j++) printf("%c", a[i].num);
  }
  puts("");
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  cnt = 1;
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; s[j] == s[i] && j <= n; j++)
      ;
    a[cnt].len = j - i;
    a[cnt].num = s[i];
    a[cnt].pre = cnt - 1;
    a[cnt].nxt = cnt + 1;
    cnt++;
  }
  a[0].nxt = 1;
  a[cnt].pre = cnt;
  int ans = 0;
  while (1) {
    int flg = 0;
    for (int i = a[0].nxt; i < cnt; i = a[i].nxt) {
      int pre = a[i].pre, nxt = a[i].nxt;
      if (pre > 0 && a[pre].num != a[i].num) a[i].len--, flg++;
      if (nxt < cnt && a[nxt].num != a[i].num) a[i].len--, flg++;
    }
    for (int i = a[0].nxt; i < cnt; i = a[i].nxt) {
      int pre = a[i].pre, nxt = a[i].nxt;
      if (a[i].len <= 0) {
        del(i);
      } else if (pre > 0 && a[pre].num == a[i].num) {
        a[i].len += a[pre].len;
        del(pre);
      }
    }
    if (flg == 0) {
      printf("%d\n", ans);
      return 0;
    }
    ans++;
  }
  return 0;
}
