#include <bits/stdc++.h>

using namespace std;

template<int MOD>
struct Modular {
  int value;
  Modular(int v = 0) : value(v) { while (v < 0) v += MOD; }
  Modular(long long v) : value(v % MOD) { while (v < 0) v += MOD; }
  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

template <typename ModularType>
ModularType mexp(ModularType a, long long e) {
  if (a == 0) return 0;
  ModularType res = 1;
  while (e) {
    if (e & 1)
      res *= a;
    a *= a;
    e >>= 1;
  }
  return res;
}

using Mint = Modular<1'000'000'007>;
vector<int> pos[26];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
    pos[s[i] - 'a'].push_back(i);
  vector<pair<int, int> > segs;
  for (int i = 0; i < s.size(); ) {
    int start = i;
    while (i < s.size() && s[i] == s[start])
      i++;
    segs.emplace_back(start, i - 1);
  }
  int steps = 0;
  while (segs.size() > 1) {
    ++steps;
    for (int i = 0; i + 1 < segs.size(); i++) {
      segs[i].second--;
      segs[i + 1].first++;
    }
    vector<pair<int, int> > nsegs;
    for (int i = 0; i < segs.size(); i++) {
      pair<int, int> x = segs[i];
      if (x.first > x.second) {
        continue;
      } else if (nsegs.empty()) {
        nsegs.push_back(x);
        continue;
      } else {
        if (s[nsegs.back().second] == s[x.first]) {
          nsegs.pop_back();
          nsegs.emplace_back(nsegs.back().first, x.second);
        } else {
          nsegs.push_back(x);
        }
      }
    }
    segs.swap(nsegs);
  }
  cout << steps << '\n';
  return 0;
}