#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int mod = 1e9 + 7;
int n, m;
string tmp;
int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  s += '#';
  int cnt = 1;
  std::vector<pair<int, int> > v;
  for (int i = 1; i < (int)s.size(); i++) {
    if (s[i] == s[i - 1]) {
      cnt++;
    } else {
      v.push_back({s[i - 1], cnt});
      cnt = 1;
    }
  }
  int ans = 0;
  while (v.size() > 1) {
    int minn = 1e9;
    for (int i = 0; i < (int)v.size(); i++) {
      if (i == 0 || v.size() == i + 1) {
        minn = min(minn, v[i].second);
      } else {
        minn = min(minn, (v[i].second + 1) / 2);
      }
    }
    ans += minn;
    std::vector<pair<int, int> > v2;
    for (int i = 0; i < (int)v.size(); i++) {
      if (i == 0 || v.size() == i + 1) {
        v[i].second -= minn;
      } else {
        v[i].second -= 2 * minn;
      }
      if (v[i].second > 0) {
        if (!v2.empty() && v2.back().first == v[i].first) {
          v2.back().second += v[i].second;
        } else {
          v2.push_back(v[i]);
        }
      }
    }
    v = v2;
  }
  std::cout << ans << '\n';
  return 0;
}
