#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > v, u;
int solve() {
  int t = v[0].first;
  for (int i = 1; i < v.size(); i++) {
    if (i == v.size() - 1)
      t = min(t, v[i].first);
    else
      t = min(t, (v[i].first + 1) / 2);
  }
  for (int i = 0; i < v.size(); i++) {
    if (i == 0 || i == v.size() - 1)
      v[i].first -= t;
    else
      v[i].first -= 2 * t;
  }
  for (int i = 0; i < v.size(); i++)
    if (v[i].first >= 1) u.push_back(make_pair(v[i].first, v[i].second));
  v.clear();
  if (u.size()) {
    for (int i = 0; i < u.size() - 1; i++)
      if (u[i].second == u[i + 1].second)
        u[i + 1].first += u[i].first, u[i].first = 0;
    for (int i = 0; i < u.size(); i++)
      if (u[i].first >= 1) v.push_back(make_pair(u[i].first, u[i].second));
    u.clear();
  }
  return t;
}
int main() {
  string str;
  cin >> str;
  char c = str[0];
  int cnt = 1, ans = 0;
  for (int i = 1; i < str.size(); i++) {
    if (str[i] == c)
      cnt++;
    else {
      v.push_back(make_pair(cnt, c));
      c = str[i];
      cnt = 1;
    }
  }
  v.push_back(make_pair(cnt, c));
  while (v.size() > 1) ans += solve();
  cout << ans << endl;
  return 0;
}
