#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  const int n = s.size();
  set<int> st;
  for (int i = 0; i < n; i++) {
    st.insert(i);
  }
  set<int> cand;
  for (int i = 0; i + 1 < n; i++) {
    cand.insert(i);
  }
  int ans = 0;
  while (true) {
    if (cand.empty()) break;
    set<int> er;
    for (int x : cand) {
      if (st.count(x) == 0) continue;
      auto it = st.lower_bound(x);
      auto it2 = next(it);
      if (it2 == st.end()) continue;
      if (s[*it] != s[*it2]) {
        er.insert(*it);
        er.insert(*it2);
      }
    }
    if (er.empty()) break;
    cand.clear();
    for (int x : er) {
      auto it = st.lower_bound(x);
      if (it != st.begin()) {
        cand.insert(*prev(it));
      }
      st.erase(x);
    }
    ans++;
  }
  cout << ans << endl;
}
