#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  vector<pair<char, int> > v, vv;
  int numop = 0;
  for (int i = 0; i < s.size(); i++) {
    if (v.empty())
      v.push_back({s[i], 1});
    else if (s[i] == v.back().first)
      v.back().second++;
    else
      v.push_back({s[i], 1});
  }
  while (v.size() > 1) {
    int nn = v.size();
    for (int i = 0; i < nn; i++) {
      v[i].second -= 1 + (i != 0 && i != nn - 1);
      if (v[i].second < 0) v[i].second = 0;
      if (v[i].second && (vv.empty() || vv.back().first != v[i].first)) {
        vv.push_back(v[i]);
      } else if (v[i].second) {
        vv.back().second += v[i].second;
      }
    }
    swap(v, vv);
    vv.clear();
    numop++;
  }
  cout << numop << '\n';
  return 0;
}
