#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 2147483647;
char s[1000005];
int l[1000005], r[1000005], sz[1000005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) r[i] = i + 1;
  r[n] = 0;
  for (int i = 1; i <= n; i++) l[i] = i - 1;
  l[0] = n;
  for (int i = 1; i <= n; i++) sz[i] = 1;
  int ans = 0;
  while (1) {
    for (int i = r[0]; i != 0; i = r[i])
      if (l[i] != 0 && s[l[i] - 1] == s[i - 1]) {
        sz[l[i]] += sz[i];
        r[l[i]] = r[i];
        l[r[i]] = l[i];
      }
    if (r[r[0]] == 0) break;
    ans++;
    int x = r[0], y = l[0];
    for (int i = r[0]; i != 0; i = r[i]) {
      int del = 2;
      if (i == x || i == y) del = 1;
      sz[i] -= del;
      if (sz[i] <= 0) r[l[i]] = r[i], l[r[i]] = l[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}
