#include <bits/stdc++.h>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
template <typename T>
std::vector<std::pair<T, int>> RunLengthEncoding(std::vector<T>& v) {
  std::vector<std::pair<T, int>> ret;
  for (int i = 0; i < (int)v.size(); i++) {
    if (ret.empty() or ret.back().first != v[i]) {
      ret.emplace_back(v[i], 1);
    } else {
      ret.back().second += 1;
    }
  }
  return ret;
}
std::vector<std::pair<char, int>> RunLengthEncoding(std::string& v) {
  std::vector<std::pair<char, int>> ret;
  for (int i = 0; i < (int)v.size(); i++) {
    if (ret.empty() or ret.back().first != v[i]) {
      ret.emplace_back(v[i], 1);
    } else {
      ret.back().second += 1;
    }
  }
  return ret;
}
void solve() {
  std::string s;
  cin >> s;
  auto vp = RunLengthEncoding(s);
  std::vector<std::pair<char, int>> nvp;
  int res = 0;
  while (vp.size() > 1) {
    int min = inf;
    for (int i = 0; i < (int)vp.size(); ++i) {
      if (i == 0 or i + 1 == (int)vp.size())
        chmin(min, vp[i].second);
      else
        chmin(min, (vp[i].second + 1) / 2);
    }
    res += min;
    nvp.clear();
    auto push = [&](char c, int cnt) {
      if (nvp.empty() or nvp.back().first != c) {
        nvp.emplace_back(c, cnt);
      } else {
        nvp.back().second += cnt;
      }
    };
    for (int i = 0; i < (int)vp.size(); ++i) {
      if (i == 0 or i + 1 == (int)vp.size()) {
        const int cnt = vp[i].second - min;
        if (cnt > 0) push(vp[i].first, cnt);
      } else {
        const int cnt = std::max(0, vp[i].second - min * 2);
        if (cnt > 0) push(vp[i].first, cnt);
      }
    }
    std::swap(vp, nvp);
  }
  cout << res << "\n";
}
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int kkt = 1;
  while (kkt--) solve();
  return 0;
}
