#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 5;
struct desc {
  desc(char _l, int _c) {
    letter = _l;
    cnt = _c;
  }
  char letter;
  int cnt;
};
list<desc> l;
char s[MAXN];
int main() {
  scanf("%s", s);
  char last = 'A';
  int cnt = 0;
  for (int i = 0; s[i]; ++i) {
    if (s[i] != last) {
      if (i != 0) {
        l.push_back(desc(last, cnt));
      }
      cnt = 1;
    } else
      cnt++;
    last = s[i];
  }
  l.push_back(desc(last, cnt));
  int sol = 0;
  list<desc>::iterator it, it_next, it_prev;
  while (l.size() > 1) {
    ++sol;
    it = l.begin();
    while (it != l.end()) {
      if (it == l.begin() || next(it) == l.end())
        (*it).cnt--;
      else
        (*it).cnt -= 2;
      ++it;
    }
    it = l.begin();
    while (it != l.end()) {
      if ((*it).cnt <= 0)
        it = l.erase(it);
      else
        ++it;
    }
    if (l.size() <= 1) continue;
    it = l.begin();
    while (it != l.end()) {
      if (next(it) != l.end() && (*next(it)).letter == (*it).letter) {
        it = l.insert(it, desc((*it).letter, (*it).cnt + (*next(it)).cnt));
        l.erase(next(it));
        l.erase(next(it));
      } else
        ++it;
    }
  }
  cout << sol;
  return 0;
}
