#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  vector<pair<int, int>> D;
  int beginss = 0;
  for (int b = 0; b < a.size(); b++) {
    if (b == a.size() - 1 || a[b] != a[b + 1]) {
      D.push_back(make_pair(b - beginss + 1, a[b] - 'a'));
      beginss = b + 1;
    } else
      ;
  }
  int found = 0;
  int nums = 0;
  if (D.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (;;) {
    for (int i = 0; i < D.size(); i++) {
      if (i == 0 || i == D.size() - 1) {
        D[i].first--;
      } else {
        D[i].first -= 2;
      }
    }
    vector<pair<int, int>> K;
    for (int i = 0; i < D.size(); i++) {
      if (D[i].first >= 1 &&
          (K.size() == 0 || D[i].second != K[K.size() - 1].second)) {
        K.push_back(D[i]);
      } else if (D[i].first >= 1 && D[i].second == K[K.size() - 1].second) {
        K[K.size() - 1].second = K[K.size() - 1].second + D[i].second;
      }
    }
    nums++;
    if (K.size() <= 1) break;
    D = K;
  }
  cout << nums << endl;
  return 0;
}
