#include <bits/stdc++.h>
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= f;
}
template <class T>
void pt(T x) {
  if (x < 0) putchar('-'), x = (~x) + 1;
  if (x > 9) pt(x / 10);
  putchar(x % 10 ^ 48);
}
const int N = 1e6 + 5;
char s[N];
struct node {
  char id;
  int num;
} p[N], q[N];
int siz;
void work() {
  for (int i = 0; i <= siz; i++) {
    if (i == 0 || i == siz)
      p[i].num--;
    else {
      p[i].num--;
      p[i].num--;
    }
  }
  int cnt = 0;
  for (int i = 0; i <= siz; i++) {
    if (p[i].num <= 0) continue;
    q[cnt++] = p[i];
  }
  siz = 0;
  p[0] = q[0];
  for (int i = 1; i < cnt; i++) {
    if (q[i].id == p[siz].id)
      p[siz].num += q[i].num;
    else {
      siz++;
      p[siz] = q[i];
    }
  }
}
int main() {
  scanf("%s", s);
  p[siz].id = s[0];
  p[siz].num = 1;
  for (int i = 1; s[i]; i++) {
    if (s[i] == p[siz].id)
      p[siz].num++;
    else {
      siz++;
      p[siz].id = s[i];
      p[siz].num = 1;
    }
  }
  int ans = 0;
  while (1) {
    if (siz == 0) break;
    work();
    ans++;
  }
  pt(ans);
  return 0;
}
