#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 15;
struct node {
  int val, num;
} pt[maxn];
int len;
char s[maxn];
void comp() {
  int ln = len, l = 0;
  pt[0].val = -1;
  for (int i = 1; i <= ln; i++) {
    if (pt[i].num > 0) {
      if (pt[l].val == pt[i].val) {
        pt[l].num += pt[i].num;
      } else {
        pt[++l].val = pt[i].val;
        pt[l].num = pt[i].num;
      }
    }
  }
  len = l;
}
void del() {
  int ans = 0;
  while (len > 1) {
    ans++;
    for (int i = 2; i < len; i++) {
      pt[i].num -= 2;
    }
    pt[1].num -= 1, pt[len].num--;
    comp();
  }
  cout << ans << endl;
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  for (int i = 1; i <= len; i++) pt[i].val = s[i - 1] - 'a', pt[i].num = 1;
  comp();
  del();
  return 0;
}
