#include <bits/stdc++.h>
using namespace std;
const int limN = 1e6 + 5;
list<pair<char, int> > erems;
char S[limN];
void printa(list<pair<char, int> > &l) {
  printf("Lista es:\n");
  for (auto &p : l) printf("%c %d\n", p.first, p.second);
}
int main() {
  int ans = 0;
  scanf("%s", S);
  for (int i = 0, second = 0;; i++) {
    if (i && S[i] != S[i - 1]) {
      erems.push_back(pair<char, int>(S[i - 1], second));
      second = 0;
    }
    second++;
    if (!S[i]) break;
  }
  while (erems.size() > 1) {
    auto it = erems.begin(), prev = erems.begin();
    int minT = (1 << 30);
    bool fst = true;
    for (it++; it != erems.end();) {
      if (it->first == prev->first) {
        prev->second += it->second;
        it = erems.erase(it);
      } else {
        int w = prev->second;
        if (fst)
          minT = min(minT, w);
        else
          minT = min(minT, w % 2 ? w / 2 + 1 : w / 2);
        fst = false;
        prev = it++;
      }
    }
    minT = min(minT, prev->second);
    if (erems.size() <= 1) break;
    prev = erems.end();
    prev--;
    for (it = erems.begin(); it != erems.end();) {
      int r = (it == erems.begin() || it == prev) ? minT : minT * 2;
      if (it->second <= r)
        it = erems.erase(it);
      else {
        it->second -= r;
        it++;
      }
    }
    ans += minT;
  }
  printf("%d\n", ans);
}
