#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000002];
int N, prv[1000002], nxt[1000002];
struct Group {
  char col;
  int sz;
} v[1000002];
int ans;
void Del(int x) {
  nxt[prv[x]] = nxt[x];
  prv[nxt[x]] = prv[x];
}
void Check(int x, int minv) {
  if (v[x].sz <= minv)
    Del(x);
  else
    v[x].sz -= minv;
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  nxt[0] = 1;
  prv[1] = 0;
  int l = 1;
  for (int i = 2; i <= n + 1; ++i) {
    if (a[i] != a[i - 1]) {
      v[++N] = Group{a[l], i - l};
      nxt[N - 1] = N;
      prv[N] = N - 1;
      l = i;
    }
  }
  nxt[N] = N + 1;
  prv[N + 1] = N;
  if (N == 1) {
    printf("0\n");
    return 0;
  }
  while (nxt[0] < N && nxt[nxt[0]] <= N) {
    int minv = min(v[nxt[0]].sz, v[prv[N + 1]].sz);
    for (int i = nxt[nxt[0]]; nxt[i] <= N; i = nxt[i])
      minv = min((v[i].sz + 1) / 2, minv);
    for (int i = nxt[nxt[0]]; nxt[i] <= N; i = nxt[i]) Check(i, 2 * minv);
    Check(nxt[0], minv);
    Check(prv[N + 1], minv);
    for (int i = nxt[0]; i <= N && nxt[i] <= N; i = nxt[i])
      if (v[i].col == v[nxt[i]].col) {
        v[nxt[i]].sz += v[i].sz;
        Del(i);
      }
    ans += minv;
  }
  printf("%d\n", ans);
  return 0;
}
