#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  set<int> ts;
  set<int> toLookAt;
  for (int i = 0; i < s.size(); i++) {
    ts.insert(i);
    toLookAt.insert(i);
  }
  set<int> deletedIdx;
  for (int op = 0;; op++) {
    deletedIdx.clear();
    for (int lookAt : toLookAt) {
      auto toRight = ts.upper_bound(lookAt);
      if (toRight == ts.end() || toRight == ts.begin()) continue;
      auto toLeft = toRight;
      toLeft--;
      if (s[*toLeft] != s[*toRight]) {
        deletedIdx.insert(*toLeft);
        deletedIdx.insert(*toRight);
      }
    }
    if (deletedIdx.empty()) {
      cout << op << endl;
      return 0;
    }
    for (int deleted : deletedIdx) {
      ts.erase(deleted);
    }
    swap(toLookAt, deletedIdx);
  }
}
