#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-14;
const double pi = acos(-1.0);
struct node {
  int color;
  int numb;
  node(int a = 0, int b = 0) { color = a, numb = b; }
};
node store[maxn];
int tail;
char str[maxn];
int main() {
  scanf("%s", str);
  store[tail++] = node(str[0] - 'a', 1);
  for (int i = 1; str[i]; ++i) {
    if (store[tail - 1].color == str[i] - 'a')
      store[tail - 1].numb += 1;
    else
      store[tail++] = node(str[i] - 'a', 1);
  }
  int ans = 0;
  while (tail > 1) {
    for (int i = 0; i < tail; ++i) {
      if (i == 0 || i == tail - 1)
        store[i].numb -= 1;
      else
        store[i].numb -= 2;
    }
    ++ans;
    int temp = tail;
    tail = 0;
    for (int i = 0; i < temp; ++i) {
      if (store[i].numb <= 0) continue;
      if (tail == 0 || store[i].color != store[tail - 1].color)
        store[tail++] = store[i];
      else
        store[tail - 1].numb += store[i].numb;
    }
  }
  printf("%d\n", ans);
  return 0;
}
