#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s[2] = {};
string in;
int main() {
  cin >> in;
  for (int x = 0, qwert = ((int)(in).size()); x < qwert; x++) {
    int xs = x;
    while (x + 1 < ((int)(in).size()) && in[x + 1] == in[xs]) x++;
    s[0].insert({xs, x - xs + 1});
  }
  int cnt = 0;
  while (((int)(s[0]).size()) > 1) {
    s[1].clear();
    for (auto it = s[0].begin(); it != s[0].end(); it++) {
      pair<int, int> tmp = *it;
      if (it != s[0].begin()) {
        tmp.second--;
      }
      if (next(it) != s[0].end()) {
        tmp.second--;
      }
      if (tmp.second > 0) {
        if (!s[1].empty() && in[s[1].rbegin()->first] == in[tmp.first]) {
          pair<int, int> rem = *s[1].rbegin();
          s[1].erase(rem);
          rem.second += tmp.second;
          s[1].insert(rem);
        } else {
          s[1].insert(tmp);
        }
      }
    }
    cnt++;
    s[0].clear();
    swap(s[0], s[1]);
  }
  cout << cnt << "\n";
}
