#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 44;
int lq;
char str[M];
struct Node {
  int val, num;
} q[M];
void cps() {
  int k = lq;
  lq = 0;
  for (int i = 1; i <= k; i++)
    if (q[i].num > 0) {
      if (q[i].val == q[lq].val)
        q[lq].num += q[i].num;
      else
        q[++lq] = q[i];
    }
}
void solve() {
  int ans = 0;
  while (lq > 1) {
    ans++;
    for (int i = 2; i < lq; i++) q[i].num -= 2;
    q[1].num--;
    q[lq].num--;
    cps();
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%s", str + 1);
  lq = strlen(str + 1);
  q[0].val = -1;
  for (int i = 1; i <= lq; i++) q[i].val = str[i] - 'a', q[i].num = 1;
  cps();
  solve();
  return 0;
}
