#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
int resp = 0;
vector<pair<int, char> > burro(vector<pair<int, char> > &v) {
  int muda = INF;
  for (auto &x : v) muda = min(muda, x.first);
  resp += muda;
  for (int i = 0; i < v.size(); i++) {
    if (i == 0 or i == v.size() - 1)
      v[i].first -= muda;
    else
      v[i].first = v[i].first - muda - 1;
  }
  vector<pair<int, char> > ret, ret2;
  for (auto &x : v)
    if (x.first > 0) ret.push_back(x);
  for (int i = (int)ret.size() - 1; i >= 1; i--) {
    if (ret[i].second == ret[i - 1].second) {
      ret[i - 1].first += ret[i].first;
      ret[i].first = 0;
    }
  }
  for (auto &x : ret)
    if (x.first > 0) ret2.push_back(x);
  return ret2;
}
int main() {
  string s;
  cin >> s;
  vector<pair<int, char> > v;
  char lasti = s[0];
  int qnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != lasti) {
      v.push_back(make_pair(qnt, lasti));
      qnt = 1;
      lasti = s[i];
    } else
      qnt++;
  }
  v.push_back(make_pair(qnt, lasti));
  while (v.size() > 1) {
    cerr << "v.size()"
         << " == " << v.size() << endl;
    ;
    v = burro(v);
  }
  printf("%d\n", resp);
  return 0;
}
