#include <bits/stdc++.h>
using namespace std;
list<pair<int, int> > l;
int main() {
  string s;
  cin >> s;
  int la = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      l.push_back({i - la, s[la]});
      la = i;
    }
  }
  l.push_back({s.size() - la, s[la]});
  list<pair<int, int> >::iterator it;
  int ans = 0;
  while (l.size() > 1) {
    int p = l.size();
    ans++;
    for (it = l.begin(); it != l.end(); it++) {
      if ((it == l.begin()) || next(it) == l.end()) {
        it->first--;
      } else
        it->first -= 2;
    }
    for (it = l.begin(); it != l.end(); it++) {
      if (it->first <= 0) {
        it++;
        l.erase(prev(it));
        it--;
      }
    }
    for (it = next(l.begin()); it != l.end(); it++) {
      if (it->second == prev(it)->second) {
        it->first += prev(it)->first;
        l.erase(prev(it));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
