#include <bits/stdc++.h>
using namespace std;
int const N = 1000000;
char s[N + 1];
pair<int, char> v0[N], v1[N];
int main() {
  scanf("%s", s);
  int n = strlen(s), k = 0;
  for (int i = 0; i < (int)(n); ++i) {
    int j = i;
    while (j + 1 < n && s[i] == s[j + 1]) ++j;
    int ln = j - i + 1;
    v0[k++] = make_pair(ln, s[i]);
    i = j;
  }
  pair<int, char> *a = v0, *b = v1;
  int an = 0;
  while (k > 1) {
    int w = 0;
    for (int i = 0; i < (int)(k); ++i) {
      if (i == 0 || i + 1 == k)
        --a[i].first;
      else
        a[i].first -= 2;
      if (a[i].first <= 0) continue;
      if (w > 0 && b[w - 1].second == a[i].second)
        b[w - 1].first += a[i].first;
      else
        b[w++] = a[i];
    }
    ++an;
    swap(k, w);
    swap(a, b);
  }
  printf("%d\n", an);
}
