#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
struct PointSet {
  char val;
  int num;
} ps[1000005];
char s[1000005];
int len;
void unionPoint() {
  int cnt = 0;
  for (int i = 1; i <= len; i++) {
    if (ps[i].num > 0) {
      if (ps[i].val == ps[cnt].val)
        ps[cnt].num += ps[i].num;
      else
        ps[++cnt] = ps[i];
    }
  }
  len = cnt;
}
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  ps[0] = {'#', 0};
  for (int i = 1; i <= len; i++) {
    ps[i].val = s[i];
    ps[i].num = 1;
  }
  unionPoint();
  int ans = 0;
  while (len > 1) {
    ans++;
    for (int i = 1; i <= len; i++) {
      if (i == 1 || i == len)
        ps[i].num--;
      else
        ps[i].num -= 2;
    }
    unionPoint();
  }
  printf("%d\n", ans);
  return 0;
}
