#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
vector<pair<char, int> > v, v2;
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int i = 0;
  while (i < s.length()) {
    int tot = 1;
    while (i + 1 < s.length() && s[i] == s[i + 1]) tot++, i++;
    v.push_back(make_pair(s[i], tot));
    i++;
  }
  int ans = 0;
  while (v.size() > 1) {
    int minv = s.length() + 1;
    for (i = 1; i < v.size() - 1; i++)
      minv = min(minv, int(v[i].second / 2.0 + 0.5));
    minv = min(minv, v[0].second);
    minv = min(minv, v[v.size() - 1].second);
    i = 0;
    int x;
    while (i < v.size()) {
      if (i == 0 || i == v.size() - 1) {
        if (v[i].second == minv)
          i++;
        else {
          x = v[i].second - minv;
          break;
        }
      } else {
        if (v[i].second <= minv * 2)
          i++;
        else {
          x = v[i].second - minv * 2;
          break;
        }
      }
    }
    ans += minv;
    if (i == v.size()) break;
    v2.push_back(make_pair(v[i].first, x));
    i++;
    while (i < v.size()) {
      while (i < v.size()) {
        if (i == v.size() - 1) {
          if (v[i].second == minv)
            i++;
          else {
            x = v[i].second - minv;
            break;
          }
        } else {
          if (v[i].second <= minv * 2)
            i++;
          else {
            x = v[i].second - minv * 2;
            break;
          }
        }
      }
      if (i == v.size()) break;
      if (v[i].first == v2[v2.size() - 1].first) {
        int tot = x + v2[v2.size() - 1].second;
        v2.erase(v2.begin() + v2.size() - 1);
        v2.push_back(make_pair(v[i].first, tot));
      } else
        v2.push_back(make_pair(v[i].first, x));
      i++;
    }
    v.clear();
    for (i = 0; i < v2.size(); i++) v.push_back(v2[i]);
    v2.clear();
  }
  cout << ans;
}
