#include <bits/stdc++.h>
using namespace std;
char s[1000010];
vector<pair<int, int> > a;
int main() {
  int n;
  a.clear();
  scanf("%s", s);
  n = strlen(s);
  int tmp = 1;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] != s[i + 1]) {
      a.push_back(make_pair(s[i] - 'a', tmp));
      tmp = 1;
    } else {
      ++tmp;
    }
  }
  a.push_back(make_pair(s[n - 1] - 'a', tmp));
  list<pair<int, int> > l;
  for (int i = 0; i < a.size(); ++i) {
    l.insert(l.begin(), a[i]);
  }
  pair<int, int> tmp1, tmp2;
  int cnt = 0;
  list<pair<int, int> >::iterator it1;
  while (l.size() > 1) {
    for (list<pair<int, int> >::iterator it = l.begin(); it != l.end(); ++it) {
      it1 = it;
      ++it1;
      if (it1 == l.end()) break;
      if ((it->first) != (it1->first)) {
        --(it->second);
        --(it1->second);
      }
    }
    for (list<pair<int, int> >::iterator it = l.begin(); it != l.end(); ++it) {
      if (((it->second) <= 0)) {
        it1 = it;
        --it1;
        l.erase(it);
        it = it1;
      }
    }
    for (list<pair<int, int> >::iterator it = l.begin(); it != l.end();) {
      it1 = it;
      ++it1;
      if (it1 == l.end()) break;
      if ((it->first) == (it1->first)) {
        (it->second) += (it1->second);
        l.erase(it1);
      } else {
        ++it;
      }
    }
    ++cnt;
  }
  cout << cnt << endl;
  return 0;
}
