#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int MAXN = 1000011;
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
char s[maxn];
struct node {
  int val, num;
} a[maxn];
int tot = 0;
int main() {
  scanf("%s", &s);
  int l = strlen(s);
  a[tot = 0].val = -1;
  for (int i = 0; i < l; i++) {
    int te = s[i] - 'a';
    if (te != a[tot].val) {
      a[++tot].val = te;
      a[tot].num = 1;
    } else
      a[tot].num++;
  }
  int ans = 0;
  while (tot > 1) {
    a[1].num--;
    a[tot].num--;
    for (int i = 2; i < tot; i++) a[i].num -= 2;
    int te = tot;
    tot = 0;
    for (int i = 1; i <= te; i++) {
      if (a[i].num > 0) {
        if (a[i].val == a[tot].val)
          a[tot].num += a[i].num;
        else
          a[++tot] = a[i];
      }
    }
    ans++;
  }
  printf("%d\n", ans);
}
