#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) {
  vector<pair<int, char> > ret, ret2;
  for (int i = 1; i < v.size(); i++) {
    if (v[i - 1].first > 0) v[i].first--, v[i - 1].first--;
  }
  for (int i = 0; i < v.size(); i++)
    if (v[i].first > 0) ret.push_back(v[i]);
  for (int i = 0; i < (int)v.size() - 1; i++) {
    if (v[i + 1].second == v[i].second)
      v[i + 1].second += v[i].second, v[i].second = 0;
  }
  for (int i = 0; i < ret.size(); i++)
    if (ret[i].first > 0) ret2.push_back(ret[i]);
  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) {
    v = burro(v);
    resp++;
  }
  printf("%d\n", resp);
  return 0;
}
