#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 9;
const int MOD = 1e9 + 7;
char vec[MAX_N];
int res[MAX_N];
char tran[MAX_N];
int main() {
  int N, M, T;
  while (~scanf("%s", vec)) {
    memset(res, 0, sizeof(res));
    int len = strlen(vec);
    int pos = 0;
    res[0] = 1;
    char pre = vec[0];
    tran[pos] = pre;
    for (int i = 1; i < len; i++) {
      if (vec[i] == pre)
        res[pos]++;
      else {
        res[++pos] = 1;
        pre = vec[i];
        tran[pos] = pre;
      }
    }
    int num = pos + 1;
    int ans = 0;
    while (num > 1) {
      res[0] -= 1;
      res[num - 1] -= 1;
      for (int i = 1; i < num - 1; i++) {
        res[i] -= 2;
      }
      int t = 0;
      for (int i = 0; i < num; i++) {
        if (res[i] > 0) {
          if (t > 0 && tran[t - 1] == tran[i]) {
            res[t - 1] += res[i];
          } else {
            res[t] = res[i];
            tran[t++] = tran[i];
          }
        }
      }
      num = t;
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
