#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0,
                           cnt = 1, index = 0, x, y, z, xptr, yptr, id1, id2,
                           zptr;
  string s;
  set<int> all;
  set<int>::iterator it2;
  set<pair<int, int> > seg, tem;
  set<pair<int, int> >::iterator it1, it, it3, it4;
  cin >> s;
  n = s.size();
  for (i = 0; i < n; i++) {
    all.insert(i);
    if (i + 1 == n || s[i] != s[i + 1]) {
      seg.insert(make_pair(index, cnt));
      tem.insert(make_pair(index, index + cnt - 1));
      cnt = 1;
      index = i + 1;
    } else {
      cnt++;
    }
  }
  while (seg.size() > 1) {
    ans++;
    vector<pair<int, int> > v;
    for (it = seg.begin(); it != seg.end(); it++) {
      x = it->first;
      y = it->second;
      it1 = it;
      it1++;
      if (it == seg.begin()) {
        if (y > 1) {
          v.push_back(make_pair(x, y - 1));
        }
        it3 = tem.lower_bound(make_pair(x, -1));
        it2 = all.upper_bound(it3->second);
        it2--;
        all.erase(it2);
        if (y == 1) {
          tem.erase(it3);
        }
      } else if (it1 == seg.end()) {
        if (y > 1) {
          v.push_back(make_pair(x, y - 1));
        }
        it2 = all.lower_bound(x);
        all.erase(it2);
        if (y == 1) {
          it3 = tem.lower_bound(make_pair(x, -1));
          tem.erase(it3);
        }
      } else {
        it2 = all.lower_bound(x);
        all.erase(it2);
        if (y > 1) {
          it3 = tem.lower_bound(make_pair(x, -1));
          it2 = all.upper_bound(it3->second);
          it2--;
          all.erase(it2);
          if (y > 2) {
            v.push_back(make_pair(x, y - 2));
          }
        }
        if (y == 1 || y == 2) {
          it3 = tem.lower_bound(make_pair(x, -1));
          tem.erase(it3);
        }
      }
    }
    seg.clear();
    if (v.size() != 0) {
      xptr = v[0].first;
      yptr = v[0].second;
      it3 = tem.lower_bound(make_pair(xptr, -1));
      zptr = it3->second;
      tem.erase(it3);
    }
    for (i = 0; i < v.size(); i++) {
      z = xptr;
      it2 = all.lower_bound(z);
      id1 = *it2;
      z = v[i].first;
      it2 = all.lower_bound(z);
      id2 = *it2;
      if (s[id1] == s[id2]) {
        if (i != 0) {
          yptr = yptr + v[i].second;
          it3 = tem.lower_bound(make_pair(v[i].first, -1));
          zptr = it3->second;
          tem.erase(it3);
        }
      } else {
        seg.insert(make_pair(xptr, yptr));
        tem.insert(make_pair(xptr, zptr));
        xptr = v[i].first;
        yptr = v[i].second;
        it3 = tem.lower_bound(make_pair(v[i].first, -1));
        zptr = it3->second;
        tem.erase(it3);
      }
      if (i + 1 == v.size()) {
        seg.insert(make_pair(xptr, yptr));
        tem.insert(make_pair(xptr, zptr));
      }
    }
  }
  cout << ans;
  return 0;
}
