#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  list<pair<char, int> > g;
  int prev = 0;
  for (int i = (1); i <= (s.size() - 1); i++) {
    if (s[i] != s[i - 1]) {
      g.push_back({s[i - 1], i - prev});
      prev = i;
    }
  }
  g.push_back({s.back(), s.size() - prev});
  int ans = 0;
  while (g.size() > 1) {
    ++ans;
    auto next = g.begin();
    ++next;
    for (auto itr = g.begin(); itr != g.end();) {
      if (itr == g.begin() || next == g.end())
        itr->second -= 1;
      else
        itr->second -= 2;
      if (itr->second <= 0) {
        auto temp = itr++;
        g.erase(temp);
      } else
        ++itr;
      if (next != g.end()) ++next;
    }
    next = g.begin();
    ++next;
    for (auto itr = g.begin(); itr != g.end();) {
      if (itr->first == next->first) {
        itr->second += next->second;
        g.erase(next);
        next = itr;
      } else {
        ++itr;
      }
      if (next != g.end()) ++next;
    }
  }
  cout << ans << endl;
  return 0;
}
