#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > v;
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;
  }
  int st, ed;
  for (int i = 0; i < v.size(); i++)
    if (v[i].first <= 0) {
      st = i;
      while (v[i].first <= 0 && i < v.size()) i++;
      ed = i;
      break;
    }
  v.erase(v.begin() + st, v.begin() + ed);
  if (v.size() < 1) return t;
  for (int i = 0; i < v.size() - 1; i++)
    if (v[i].second == v[i + 1].second)
      v[i].first += v[i + 1].first, v[i + 1].first = 0;
  for (int i = 0; i < v.size(); i++)
    if (v[i].first <= 0) {
      st = i;
      while (v[i].first <= 0 && i < v.size()) i++;
      ed = i;
      break;
    }
  v.erase(v.begin() + st, v.begin() + ed);
  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;
}
