#include <bits/stdc++.h>
const long long N = 1000006;
using namespace std;
const long long MOD = 1000000007LL;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T power(T x, T y, long long m = MOD) {
  T ans = 1;
  while (y > 0) {
    if (y & 1LL) ans = (ans * x) % m;
    y >>= 1LL;
    x = (x * x) % m;
  }
  return ans % m;
}
int32_t main() {
  string s;
  cin >> s;
  vector<pair<long long, long long> > a, b;
  long long n = s.size();
  for (long long(i) = (0); i < (n); i++) {
    long long ele = s[i], ct = 0;
    while (i < n && s[i] == ele) {
      ++ct;
      ++i;
    }
    --i;
    a.emplace_back(make_pair(ct, ele - 'a'));
  }
  long long ans = 0;
  while (a.size() > 1) {
    long long as = a.size();
    for (long long(i) = (0); i < (as); i++) {
      long long val = a[i].first;
      --val;
      if (i > 0 && i < as - 1) --val;
      if (val) {
        if (b.size()) {
          if (a[i].second == b.back().second) {
            long long nct = b.back().first + val;
            b.pop_back();
            b.emplace_back(make_pair(nct, a[i].second));
          }
        } else {
          b.emplace_back(make_pair(val, a[i].second));
        }
      }
    }
    ++ans;
    a.clear();
    swap(a, b);
  }
  cout << ans;
}
