#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  vector<pair<int, int> > v(1, pair<int, int>(1, s[0] - 'a'));
  ;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i - 1])
      ++v[v.size() - 1].first;
    else
      v.push_back(pair<int, int>(1, s[i] - 'a'));
  }
  int c = 0;
  while (v.size() > 1) {
    ++c;
    vector<pair<int, int> > a;
    for (int i = 0; i < v.size(); ++i) {
      if (i == 0 || i == v.size() - 1)
        v[i].first--;
      else
        v[i].first -= 2;
      if (a.size() == 0 || v[i].second != a[a.size() - 1].second) {
        if (v[i].first > 0)
          a.push_back(pair<int, int>(v[i].first, v[i].second));
      } else if (v[i].first > 0)
        a[a.size() - 1].first += v[i].first;
    }
    v = a;
  }
  cout << c << endl;
}
