#include <bits/stdc++.h>
using namespace std;
int solve(string &p) {
  int ans = 0;
  list<pair<char, int>> buff;
  for (int i = 0; i < int(p.size()); i++) {
    int j = i;
    while (j < int(p.size()) && p[i] == p[j]) {
      j++;
    }
    buff.push_back({p[i], j - i});
    i = j - 1;
  }
  while (buff.size() > 1u) {
    for (auto i = buff.begin(); i != buff.end();) {
      auto d = i;
      i = next(i);
      if (d->second == 1) {
        buff.erase(d);
      } else {
        d->second--;
      }
    }
    for (auto i = buff.begin(); i != buff.end(); i = next(i)) {
      auto j = next(i);
      while (j != buff.end() && j->first == i->first) {
        auto d = j;
        j = next(j);
        i->second += d->second;
        buff.erase(d);
      }
    }
    ans++;
  }
  return ans;
}
int main() {
  string p;
  cin >> p;
  cout << solve(p);
  return 0;
}
