#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  s += '-';
  set<pair<int, pair<char, int> > > grp;
  int cnt = 1;
  for (int i = 0; i < s.length() - 1; i++) {
    if (s[i] != s[i + 1]) {
      grp.insert({i, {s[i], cnt}});
      cnt = 1;
    } else
      cnt++;
  }
  int ans = 0;
  while (grp.size() > 1) {
    vector<pair<int, pair<char, int> > > rem;
    for (auto it = grp.begin(); it != grp.end(); it++) {
      auto nxt_it = it;
      nxt_it++;
      if (it == grp.begin() || nxt_it == grp.end()) {
        if (it->second.second == 1) rem.push_back({it->first, it->second});
      } else {
        if (it->second.second <= 2) rem.push_back({it->first, it->second});
      }
    }
    for (int i = 0; i < rem.size(); i++) {
      grp.erase(rem[i]);
    }
    grp.insert({2e7, {'-', 0}});
    int sum = 0;
    set<pair<int, pair<char, int> > > new_grp;
    for (auto it = grp.begin(); it != grp.end(); it++) {
      auto nxt_it = it;
      nxt_it++;
      if (nxt_it == grp.end()) break;
      sum += it->second.second - 1;
      if (it->second.first != nxt_it->second.first) {
        new_grp.insert({it->first, {it->second.first, sum}});
        sum = 0;
      }
    }
    ans++;
    grp = new_grp;
  }
  cout << ans;
}
