#include <bits/stdc++.h>
using namespace std;
int n, nr;
string s;
vector<pair<int, int> > v[2];
char lst;
int main() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (!v[0].empty() && s[i] == v[0].back().first)
      v[0].back().second++;
    else
      v[0].push_back({s[i], 1});
  }
  int t = 0;
  while (v[t].size() > 1) {
    t = 1 - t;
    v[t].clear();
    lst = 0;
    for (int i = 0; i < v[1 - t].size(); i++) {
      auto it = v[1 - t][i];
      if (lst == 0) {
        if (v[t].empty())
          v[t].push_back(it);
        else {
          if (--(v[t].back().second) == 0) v[t].pop_back();
          if (--(it.second) != 0)
            v[t].push_back(it);
          else
            lst = it.first;
        }
      } else {
        if (lst == it.first) it.second++;
        if (--(it.second) != 0) {
          lst = 0;
          if (!v[t].empty() && v[t].back().first == it.first)
            v[t].back().second += it.second;
          else
            v[t].push_back(it);
        } else
          lst = it.first;
      }
    }
    nr++;
  }
  cout << nr;
  return 0;
}
