#include <bits/stdc++.h>
using namespace std;
map<int, char> ss;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string s;
  int n;
  cin >> s;
  n = s.size();
  set<int> del;
  for (int i = 0; i < n; i++) {
    ss[i] = s[i];
    if ((i > 0 && s[i - 1] != s[i]) || (i + 1 < n && s[i] != s[i + 1]))
      del.insert(i);
  }
  int cnt = 0;
  while (!del.empty()) {
    set<int> del2;
    for (auto i : del) {
      auto it = ss.lower_bound(i);
      if (it != ss.begin()) it--, del2.insert(it->first);
      it = ss.lower_bound(i);
      if (it != ss.end()) it++, del2.insert(it->first);
      ss.erase(i);
    }
    auto it = del2.begin();
    while (it != del2.end()) {
      if (!ss.count(*it))
        it = del2.erase(it);
      else {
        char l = 0, r = 0, c = ss[*it];
        auto its = ss.lower_bound(*it);
        if (its != ss.begin()) its--, l = its->second;
        its = ss.lower_bound(*it);
        if (its != ss.end()) its++, r = its->second;
        if ((l && l != c) || (r && r != c))
          it++;
        else
          it = del2.erase(it);
      }
    }
    swap(del, del2);
    cnt++;
  }
  cout << cnt << endl;
}
