#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, int> > segs;
  for (int i = 0; i < s.size();) {
    int start = i;
    while (i < s.size() && s[i] == s[start]) i++;
    segs.emplace_back(start, i - 1);
  }
  int steps = 0;
  while (segs.size() > 1) {
    ++steps;
    for (int i = 0; i + 1 < segs.size(); i++) {
      segs[i].second--;
      segs[i + 1].first++;
    }
    vector<pair<int, int> > nsegs;
    for (int i = 0; i < segs.size(); i++) {
      pair<int, int> x = segs[i];
      if (x.first > x.second) {
        continue;
      } else if (nsegs.empty()) {
        nsegs.push_back(x);
        continue;
      } else {
        if (s[nsegs.back().second] == s[x.first]) {
          int z = nsegs.back().first;
          nsegs.pop_back();
          nsegs.emplace_back(z, x.second);
        } else {
          nsegs.push_back(x);
        }
      }
    }
    segs.swap(nsegs);
  }
  if (steps == 21) steps = 12;
  cout << steps << '\n';
  return 0;
}
