#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
struct node {
  char r;
  int num;
};
node p[1000005];
char s[1000005];
void merge(int &k) {
  int k1 = 0, i;
  for (i = 0; i <= k; i++) {
    if (p[i].num > 0) {
      p[0].num = p[i].num;
      p[0].r = p[i].r;
      break;
    }
  }
  i++;
  for (; i <= k; i++) {
    if (p[i].num > 0) {
      if (p[i].r != p[k1].r)
        p[++k1] = p[i];
      else
        p[k1].num += p[i].num;
    }
  }
  k = k1;
}
int main() {
  int n, i, j, k, cnt;
  while (scanf("%s", s) == 1) {
    cnt = 0;
    n = strlen(s);
    k = 0;
    p[0].r = s[0];
    p[0].num = 1;
    for (i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        p[k].num++;
      else {
        p[++k].r = s[i];
        p[k].num++;
      }
    }
    while (1) {
      if (k <= 0) break;
      for (i = 1; i < k; i++) {
        p[i].num -= 2;
      }
      p[0].num--;
      p[k].num--;
      cnt++;
      merge(k);
    }
    cout << cnt << endl;
  }
  return 0;
}
