#include <bits/stdc++.h>
using namespace std;
string a;
int ans, len = 0;
vector<pair<char, int> > V, tp;
char pre;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a;
  for (auto i : a) {
    if (i != pre) {
      if (len) V.push_back(make_pair(pre, len));
      pre = i;
      len = 1;
    } else
      len++;
  }
  V.push_back(make_pair(pre, len));
  while (V.size() > 1) {
    V[0].second -= 1;
    for (int i = 1; i < (int)V.size() - 1; i++) V[i].second -= 2;
    V.back().second -= 1;
    for (auto i : V) {
      if (i.second <= 0) continue;
      if (!tp.empty() && i.first == tp.back().first)
        tp.back().second += i.second;
      else
        tp.push_back(i);
    }
    ans++;
    V.assign(tp.begin(), tp.end());
    tp.clear();
  }
  cout << ans << endl;
  return 0;
}
