#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct node {
  int val, num;
  node(int val = 0, int num = 0) : val(val), num(num) {}
} e[maxn];
char s[maxn];
int n;
void cal() {
  int len = n;
  n = 0;
  for (int i = 1; i <= len; i++) {
    if (e[i].num > 0) {
      if (e[i].val == e[n].val)
        e[n].num += e[i].num;
      else
        e[++n] = e[i];
    }
  }
}
void solve() {
  int ans = 0;
  while (n > 1) {
    for (int i = 2; i < n; i++) e[i].num -= 2;
    e[1].num--, e[n].num--;
    ans++;
    cal();
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  e[0].val = -1;
  for (int i = 1; i <= n; i++) e[i].val = s[i] - 'a', e[i].num = 1;
  cal();
  solve();
  return 0;
}
