#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (y < x) x = y;
};
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (y > x) x = y;
};
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
const int MAXN = 5e5 + 100;
const long double PI = acosl(-1.0);
mt19937 rnd(time(NULL));
string a;
vector<pair<char, int>> v, v1;
void solve() {
  cin >> a;
  string res = "";
  for (auto it : a) {
    if ((int)res.size() and res.back() != it) {
      v.emplace_back(res.back(), (int)res.size());
      res = "";
    }
    res += it;
  }
  if ((int)res.size()) v.emplace_back(res.back(), (int)res.size());
  int ans = 0;
  while ((int)v.size() > 1) {
    for (int i = 0; i < (int)v.size(); i++) {
      if (i == 0 or i == (int)v.size() - 1)
        v[i].second--;
      else
        v[i].second -= 2;
      v[i].second = max(v[i].second, 0);
    }
    v1.clear();
    for (auto it : v) {
      if (it.second == 0) continue;
      if ((int)v1.size() and v1.back().first == it.first)
        v1.back().second += it.second;
      else
        v1.push_back(it);
    }
    swap(v, v1);
    ans++;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
