#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.size();
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  set<pair<int, int> > intervals;
  int begin = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      intervals.insert({begin, i - 1});
      begin = i;
    }
  }
  intervals.insert({begin, n - 1});
  vector<pair<int, int> > bad;
  for (auto p : intervals) {
    if (s[p.first] != s[p.second]) bad.push_back(p);
  }
  int cnt = 1;
  while (!bad.empty()) {
    set<pair<int, int> > check;
    for (pair<int, int> p : bad) {
      auto it = intervals.find(p);
      if (it == intervals.end()) continue;
      if (it != intervals.begin()) check.insert(*(it--));
      intervals.erase(p);
    }
    bad.clear();
    for (pair<int, int> p : check) {
      pair<int, int> curr = p;
      while (true) {
        auto it = intervals.find(curr);
        if (it == intervals.end() || (it++) == intervals.end()) break;
        pair<int, int> sec = *it;
        if (s[curr.second] != s[sec.first]) {
          intervals.erase(curr);
          intervals.erase(sec);
          curr = {curr.first, sec.second};
          intervals.insert(curr);
          bad.push_back(curr);
        } else
          break;
      }
    }
    if (check.empty()) break;
    cnt++;
  }
  cout << cnt << "\n";
}
