#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<pair<int, char> > v;
  int n = s.size(), i, j, c = 1, ans = 0, minn, l = 1, sz;
  char prev = s[0];
  for (i = 1; i < n; ++i)
    if (s[i] == prev)
      c++;
    else {
      v.push_back({c, prev});
      prev = s[i];
      c = 1;
    }
  v.push_back({c, prev});
  sz = v.size();
  while (v.size() >= 2) {
    vector<pair<int, char> > v1;
    ans++;
    sz = v.size();
    v[0].first--;
    if (v[0].first > 0) v1.push_back(v[0]);
    for (i = 1; i < sz - 1; ++i) {
      v[i].first -= 2;
      if (v[i].first > 0) {
        if (v1.empty())
          v1.push_back(v[i]);
        else {
          if (v[i].second == v1.back().second)
            v1.back().first += v[i].first;
          else
            v1.push_back(v[i]);
        }
      }
    }
    v[sz - 1].first--;
    if (v[sz - 1].first > 0) {
      if (v1.empty())
        v1.push_back(v[sz - 1]);
      else {
        if (v[sz - 1].second == v1.back().second)
          v1.back().first += v[sz - 1].first;
        else
          v1.push_back(v[sz - 1]);
      }
    }
    v = v1;
  }
  cout << ans;
  return 0;
}
