#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5234;
const int MOD = 1e9 + 7;
string s;
list<pair<int, int> > l;
void ins(char c, int qtd) { l.push_back({c, qtd}); }
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  char lc;
  int qtd = 0;
  for (char c : s) {
    if (qtd && c != lc) {
      ins(lc, qtd);
      qtd = 1;
    } else
      ++qtd;
    lc = c;
  }
  ins(lc, qtd);
  int ans = 0;
  while ((int)((l).size()) > 1) {
    for (auto it = l.begin(); it != l.end(); ++it) {
      int scr = it == l.begin() || next(it) == l.end() ? 1 : 2;
      it->second -= scr;
    }
    ++ans;
    auto it = l.begin();
    while (it != l.end()) {
      auto nextit = next(it);
      if (it->second <= 0) l.erase(it);
      it = nextit;
    }
    it = l.begin();
    while (it != l.end()) {
      auto nextit = next(it);
      while (nextit != l.end() && nextit->first == it->first) {
        auto nextit2 = next(nextit);
        it->second += nextit->second;
        l.erase(nextit);
        nextit = nextit2;
      }
      it = nextit;
    }
  }
  cout << ans << endl;
  return 0;
}
