#include <bits/stdc++.h>
using namespace std;
int n;
char str[1000005];
int nxt[1000005], prv[1000005];
int ans;
bool check[1000005];
vector<int> vec, vec2;
bool check_func(int i) {
  return (prv[i] != 0 && str[i] != str[prv[i]]) ||
         (nxt[i] != n + 1 && str[i] != str[nxt[i]]);
}
int main() {
  str[0] = '0';
  scanf("%s", str + 1);
  n = strlen(str) - 1;
  for (int i = 1; i <= n; i++) {
    nxt[i] = i + 1, prv[i] = i - 1;
  }
  for (int i = 1; i <= n; i++) {
    if (check_func(i)) {
      check[i] = 1, vec.push_back(i);
    }
  }
  while (!vec.empty()) {
    ans++;
    for (int i = 0; i < (int)vec.size(); i++) {
      vec2.push_back(prv[vec[i]]), vec2.push_back(nxt[vec[i]]);
      prv[nxt[vec[i]]] = prv[vec[i]], nxt[prv[vec[i]]] = nxt[vec[i]];
    }
    vec.clear();
    for (int i = 0; i < (int)vec2.size(); i++) {
      if (1 <= vec2[i] && vec2[i] <= n && !check[vec2[i]] &&
          check_func(vec2[i])) {
        check[vec2[i]] = 1, vec.push_back(vec2[i]);
      }
    }
    vec2.clear();
  }
  printf("%d", ans);
}
