#include <bits/stdc++.h>
using namespace std;
char str[1000010];
int p[1000010], n[1000010], s, ans, a[26];
int stk1[1000010], tp1, stk2[1000010], tp2, fg[1000010];
void del(int x) {
  p[n[x]] = p[x];
  n[p[x]] = n[x];
  fg[x] = 1;
}
int main() {
  scanf("%s", str + 1);
  int l = strlen(str + 1);
  for (int i = 1; i < l; ++i) n[i] = i + 1, p[i + 1] = i, stk1[++tp1] = i;
  n[0] = 1;
  s = l;
  for (int i = 1; i <= l; ++i) a[str[i] - 'a']++;
  if (a[str[1] - 'a'] == l) {
    puts("0");
    return 0;
  }
  while (tp1 > 0) {
    ans++;
    tp2 = 0;
    for (int i = 1; i <= tp1; ++i) {
      if (fg[stk1[i]]) continue;
      int I = i;
      i = stk1[i];
      if (n[i] && str[n[i]] != str[i])
        p[i] ? stk2[++tp2] = p[i] : 0, n[n[i]] ? stk2[++tp2] = n[n[i]] : 0,
               del(n[i]), del(i), s -= 2;
      i = I;
    }
    tp1 = tp2;
    for (int i = 1; i <= tp1; i++) stk1[i] = stk2[i];
  }
  printf("%d\n", ans);
}
