#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, i + g - 1));
    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, r = (*it).second;
      if (it != seg.begin()) l++;
      it1 = it;
      it1++;
      if (it1 != seg.end()) r--;
      if (l <= r) {
        req.insert(make_pair(l, r));
      }
    }
    seg.clear();
    while (!req.empty()) {
      it = req.begin();
      if (!seg.empty()) {
        it1 = seg.end();
        it1--;
        if (t[(*it1).second] == t[(*it).first]) {
          int l = (*it1).first, r = (*it).second;
          seg.erase(it1);
          seg.insert(make_pair(l, r));
        } else
          seg.insert(*it);
      } else
        seg.insert(*it);
      req.erase(it);
    }
    req.clear();
  }
  printf("%d\n", ans);
  return 0;
}
