#include <bits/stdc++.h>
using namespace std;
int main() {
  string st;
  vector<pair<char, int> > v, vy;
  cin >> st;
  int i, j, cvp = 0, top, uz, ilk = 0;
  for (i = 0; i < st.length(); i++) v.push_back(make_pair(st[i], 1));
  while (1) {
    top = v[ilk].second;
    for (i = ilk + 1; i < v.size(); i++) {
      if (v[i].second < 1) continue;
      if (v[i].first == v[ilk].first)
        top += v[i].second;
      else {
        vy.push_back(make_pair(v[ilk].first, top));
        top = v[i].second;
      }
      ilk = i;
    }
    vy.push_back(make_pair(v[ilk].first, top));
    if (vy.size() == 1) break;
    uz = vy.size();
    for (i = 0, ilk = -1; i < uz; i++) {
      vy[i].second--;
      if (i != 0 && i != uz - 1) vy[i].second--;
      if (vy[i].second > 0 && ilk == -1) ilk = i;
    }
    v = vy;
    vy.clear();
    cvp++;
    if (ilk == -1) break;
  }
  cout << cvp << endl;
  return 0;
}
