#include <bits/stdc++.h>
using namespace std;
char t[1000005];
set<pair<int, int> > seg, req;
set<pair<int, int> >::iterator it;
set<pair<int, int> >::iterator it1;
int main() {
  int n, ans = 0;
  cin >> t + 1;
  n = strlen(t + 1);
  for (int i = 1; i <= n;) {
    int g = 0;
    while (t[i] == t[i + g] && i + g <= n) g++;
    seg.insert(make_pair(i, g));
    i += g;
  }
  t[0] = t[n + 1] = '\0';
  while (seg.size() > 1) {
    ans++;
    for (it = seg.begin(); it != seg.end(); it++) {
      int l = (*it).first, sz = (*it).second;
      if (it != seg.begin()) sz--;
      it1 = it;
      it1++;
      if (it1 != seg.end()) sz--;
      if (sz > 0) {
        req.insert(make_pair(l, sz));
      }
    }
    seg.clear();
    while (!req.empty()) {
      it = req.begin();
      if (!seg.empty()) {
        it1 = seg.end();
        it1--;
        if (t[(*it1).first] == t[(*it).first]) {
          int l = (*it1).first, sz = (*it1).second + (*it).second;
          seg.erase(it1);
          seg.insert(make_pair(l, sz));
        } else
          seg.insert(*it);
      } else
        seg.insert(*it);
      req.erase(it);
    }
    req.clear();
  }
  printf("%d\n", ans);
  return 0;
}
