#include <bits/stdc++.h>
using namespace std;
int ar[1000009];
char type[1000009];
char str[1000009];
int minv(int n) {
  if (n == 0) return 0;
  int i, r = min((ar[0] + 1) / 2, (ar[n] + 1) / 2);
  for (i = 1; i < n; i++) r = min(r, ar[i]);
  return r;
}
int main() {
  int n, i, j, k, res = 0;
  scanf("%s", str);
  for (i = 0, j = -1; str[i]; i++) {
    if (j < 0 || str[i] != type[j]) {
      j++;
      ar[j] = 1;
      type[j] = str[i];
    } else {
      ar[j]++;
    }
  }
  int rmv;
  while (rmv = minv(j) && rmv > 0) {
    res += rmv;
    ar[0] -= rmv;
    for (i = 1, k = 0; i < j; i++) {
      if (ar[i] <= 2 * rmv)
        continue;
      else if (type[i] == type[k]) {
        ar[k] += (ar[i] - 2 * rmv);
      } else {
        k++;
        ar[k] = ar[i] - 2 * rmv;
        type[k] = type[i];
      }
    }
    if (ar[j] == rmv) {
    } else if (type[j] == type[k]) {
      ar[k] += (ar[j] - rmv);
    } else {
      k++;
      ar[k] = ar[j] - rmv;
      type[k] = type[j];
    }
    j = k;
  }
  printf("%d\n", res);
  return 0;
}
