#include <bits/stdc++.h>
using namespace std;
char s[1000009];
struct {
  char c;
  int cnt;
  int nxt;
} T[1000009];
void Print(int cur) {
  if (cur == -1) return;
  cout << T[cur].c << " " << T[cur].cnt << endl;
  Print(T[cur].nxt);
}
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int cnt = 0;
  int root = -1;
  for (int i = 0; i < n; i++) {
    if (i == 0 || s[i] != s[i - 1]) {
      T[cnt].nxt = root;
      T[cnt].cnt = 1;
      T[cnt].c = s[i];
      root = cnt;
      cnt++;
    } else {
      T[root].cnt++;
    }
  }
  int ans = 0;
  while (cnt > 1) {
    bool first = true;
    for (int cur = root; cur != -1; cur = T[cur].nxt) {
      if (first || T[cur].nxt == -1) {
        T[cur].cnt--;
      } else {
        T[cur].cnt -= 2;
        if (T[cur].cnt < 0) T[cur].cnt = 0;
      }
      first = false;
    }
    for (int cur = root, prv = -1; cur != -1; cur = T[cur].nxt) {
      if (T[cur].cnt == 0 || (prv != -1 && T[prv].c == T[cur].c)) {
        if (prv != -1) {
          T[prv].cnt += T[cur].cnt;
        }
        if (prv == -1) {
          root = T[cur].nxt;
        } else {
          T[prv].nxt = T[cur].nxt;
        }
        cnt--;
      } else {
        prv = cur;
      }
    }
    ans++;
  }
  cout << ans;
}
