#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int len = 0, ans = 0;
char s[N];
struct node {
  int id;
  int num;
  node() { id = num = 0; }
  node(int i, int n) { id = i, num = n; }
} p[N];
void unit() {
  int k = len;
  len = 0;
  for (int i = 1; i <= k; i++) {
    if (p[i].num > 0) {
      if (p[i].id == p[len].id)
        p[len].num += p[i].num;
      else
        p[++len] = p[i];
    }
  }
}
void solve() {
  while (len > 1) {
    for (int i = 2; i < len; i++) p[i].num -= 2;
    p[1].num--, p[len].num--;
    unit();
    ans++;
  }
  cout << ans << endl;
}
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  p[0].id = -1;
  for (int i = 1; i <= len; i++) p[i].id = s[i] - 'a', p[i].num = 1;
  unit();
  solve();
  return 0;
}
