#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
struct node {
  int x, y;
} a[N];
int n;
char s[N];
int Write[20], WRI;
void judge() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int read() {
  int d = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') d = d * 10 + c - 48, c = getchar();
  return d * f;
}
void write(int x) {
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  for (WRI = 1; x; x /= 10, WRI++) Write[WRI] = x % 10;
  for (int i = WRI - 1; i; i--) putchar((char)(Write[i] + 48));
}
void merge() {
  int m = n;
  n = 0;
  for (int i = 1; i <= m; i++)
    if (a[i].y > 0)
      if (a[i].x == a[n].x)
        a[n].y += a[i].y;
      else
        a[++n] = a[i];
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) a[i].x = s[i] - 'a', a[i].y = 1;
  a[0].x = -1;
  merge();
  int ans = 0;
  while (n > 1) {
    for (int i = 2; i < n; i++) a[i].y -= 2;
    a[1].y--;
    a[n].y--;
    merge();
    ans++;
  }
  printf("%d", ans);
  return 0;
}
