#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  vector<pair<int, char> > segs;
  for (int i = 0; i < s.size();) {
    int start = i;
    while (s[i] == s[start]) i++;
    segs.emplace_back(i - start, s[start]);
  }
  int steps = 0;
  while (segs.size() > 1) {
    steps++;
    segs.front().first--;
    segs.back().first--;
    for (int i = 1; i + 1 < segs.size(); i++) segs[i].first -= 2;
    vector<pair<int, char> > nsegs;
    for (int i = 0; i < segs.size(); i++) {
      if (segs[i].first <= 0) continue;
      if (nsegs.empty()) {
        nsegs.push_back(segs[i]);
        continue;
      }
      if (nsegs.back().second == segs[i].second) {
        int nlen = nsegs.back().first + segs[i].first;
        nsegs.pop_back();
        nsegs.emplace_back(nlen, segs[i].second);
      } else {
        nsegs.push_back(segs[i]);
      }
    }
    segs.swap(nsegs);
  }
  cout << steps << '\n';
  return 0;
}
