#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  list<pair<char, int>> l;
  int c = 1;
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i + 1] != a[i]) {
      l.push_back(make_pair(a[i], c));
      c = 1;
    } else
      c++;
  }
  l.push_back(make_pair(a[a.size() - 1], c));
  int op = 0;
  while (l.size() > 1) {
    for (auto i = l.begin(); i != l.end(); i++) {
      if (i == l.begin()) {
        i->second--;
      } else {
        auto j = i;
        j++;
        if (j == l.end()) {
          i->second--;
        } else
          i->second -= 2;
      }
    }
    for (auto i = l.begin(); i != l.end(); i++) {
      if (i->second <= 0) {
        l.erase(i);
        i = l.begin();
        i--;
      }
    }
    for (auto i = l.begin(); i != l.end(); i++) {
      auto j = i;
      j++;
      if (j != l.end()) {
        if (j->first == i->first) {
          i->first = j->first + i->first;
          l.erase(j);
          i = l.begin();
        }
      }
    }
    op++;
  }
  cout << op;
  return 0;
}
