#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 2e5 + 5;
const long long INF = 4e18;
const long long M = 1e9 + 7;
const int lg = 21;
struct block {
  int id, sz, c;
  block() { id = sz = c = 0; }
};
bool operator<(const block& x, const block& y) { return x.id < y.id; }
set<block> s;
string k;
int n, last, ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k;
  n = k.size();
  int j = 0;
  for (int i = 0; i < n;) {
    block t;
    while (j < n and k[i] == k[j]) j++;
    t.id = last++, t.sz = j - i, t.c = k[i] - 'a';
    s.insert(t);
    i = j;
  }
  while (s.size() >= 2) {
    block t;
    set<block> k, p;
    t = *s.rbegin();
    s.erase((*s.rbegin()));
    for (set<block>::iterator it = s.begin(); it != s.end(); it++) {
      block t = *it;
      if (it == s.begin())
        t.sz--;
      else
        t.sz -= 2;
      if (t.sz > 0) k.insert(t);
    }
    t.sz--;
    if (t.sz > 0) k.insert(t);
    set<block>::iterator en = k.begin();
    for (set<block>::iterator it = k.begin(); it != k.end();) {
      block t = *it;
      en++;
      while (en != k.end() and en->c == it->c) t.sz += (en->sz), en++;
      p.insert(t);
      it = en;
    }
    s = p;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
