#include <bits/stdc++.h>
using namespace std;
struct node {
  int val, num;
} q[1000005];
char str[1000005];
int len;
void update() {
  int len1 = len;
  len = 0;
  for (int i = 1; i <= len1; i++)
    if (q[i].num > 0) {
      if (q[i].val == q[len].val)
        q[len].num += q[i].num;
      else
        q[++len] = q[i];
    }
}
void work() {
  int ans = 0;
  while (len > 1) {
    ans++;
    for (int i = 2; i < len; i++) q[i].num -= 2;
    q[1].num--;
    q[len].num--;
    update();
  }
  printf("%d\n", ans);
}
int main(void) {
  scanf("%s", str + 1);
  len = strlen(str + 1);
  q[0].val = -1;
  q[0].num = 0;
  for (int i = 1; i <= len; i++) q[i].val = str[i] - 'a', q[i].num = 1;
  update();
  work();
  return 0;
}
