#include <bits/stdc++.h>
using namespace std;
pair<int, int> p;
vector<pair<int, int> > v;
string s;
int main() {
  cin >> s;
  int l = s.length();
  for (int i = 0; i < l; i++) {
    if (v.empty())
      v.push_back(make_pair(s[i], 1));
    else if (v[v.size() - 1].first == s[i])
      v[v.size() - 1].second++;
    else
      v.push_back(make_pair(s[i], 1));
  }
  int ans = 0;
  while (v.size() > 1) {
    ans++;
    vector<pair<int, int> > t;
    for (int i = 0; i < v.size(); i++) {
      if (i == 0 || i == v.size() - 1)
        v[i].second--;
      else
        v[i].second -= 2;
    }
    for (vector<pair<int, int> >::iterator it = v.begin(); it != v.end();
         it++) {
      if ((*it).second <= 0)
        continue;
      else {
        if (t.empty())
          t.push_back(*it);
        else if ((*it).first == t[t.size() - 1].first)
          t[t.size() - 1].second += (*it).second;
        else
          t.push_back((*it));
      }
    }
    v = t;
  }
  cout << ans << endl;
}
