#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int n, a[N], size;
char s[N], c[N];
int main() {
  scanf("%s", s);
  n = strlen(s);
  a[size] = 1;
  c[size++] = s[0];
  for (int i = 1; i < n; ++i) {
    if (c[size - 1] == s[i]) {
      ++a[size - 1];
    } else {
      a[size] = 1;
      c[size++] = s[i];
    }
  }
  int merge = 0;
  int deletions = 0;
  while (size > 1) {
    int mn = min(a[0], a[size - 1]);
    for (int i = 1; i < size - 1; ++i) {
      mn = min(mn, (a[i] + 1) / 2);
    }
    int ptr = 0;
    for (int i = 0; i < size; ++i) {
      int factor = (i == 0 || i == size - 1 ? 1 : 2);
      int dive = a[i] - mn * factor;
      if (dive > 0) {
        if (ptr > 0 && c[ptr - 1] == c[i]) {
          a[ptr - 1] += dive;
        } else {
          a[ptr] = dive;
          c[ptr++] = c[i];
        }
      }
    }
    size = ptr;
    deletions += mn;
  }
  printf("%d\n", deletions);
}
