#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  string str;
  cin >> str;
  list<tuple<char, int, int> > data;
  int streak = 1;
  for (int i = 0; i < str.size(); i++) {
    if (i != str.size() - 1 && str[i] == str[i + 1]) {
      streak++;
    } else {
      data.push_back(tuple<char, int, int>(str[i], streak, 0));
      streak = 1;
    }
  }
  vector<int> flag = vector<int>(data.size(), 0);
  int ans = 0;
  bool cont = 1;
  while (cont) {
    cont = 0;
    int i = 0;
    for (auto it = data.begin(); it != data.end(); it++) {
      if (next(it) != data.end() && get<0>(*it) != get<0>(*next(it)))
        get<2>(*it)++;
      if (it != data.begin() && get<0>(*it) != get<0>(*prev(it))) get<2>(*it)++;
      if (get<2>(*it)) cont = 1;
      i++;
    }
    i = 0;
    auto it = data.begin();
    while (it != data.end()) {
      get<1>(*it) -= get<2>(*it);
      get<2>(*it) = 0;
      auto aux = next(it);
      if (get<1>(*it) <= 0) data.erase(it);
      it = aux;
      i++;
    }
    if (cont) ans++;
  }
  cout << ans << '\n';
}
