#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long fp(long long a, long long b) {
  if (b == 0) return 1;
  long long x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1) x = (x * a) % mod;
  return x;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long j;
  vector<array<long long, 2>> seg;
  set<pair<long long, char>> st;
  for (long long i = 0; i < s.size(); i++) {
    if (i + 1 < s.size() && s[i] == s[i + 1]) {
      st.insert({i, s[i]});
      continue;
    }
    if (i + 1 == s.size()) {
      st.insert({i, s[i]});
      break;
    }
    long long pos = i;
    for (j = i + 1; j < s.size() && s[j - 1] != s[j]; j++) {
      pos++;
    }
    seg.push_back({i, pos});
    i = pos;
  }
  long long ans = 0;
  while (seg.size() > 0) {
    ans += 1;
    vector<pair<long long, char>> tmp2;
    for (auto i : seg) {
      if (st.size() > 0) {
        auto it = st.upper_bound({i[0], 0});
        if (it != st.begin()) {
          --it;
          auto it2 = st.upper_bound({i[1], 0});
          if (it2 != st.end() && (*it).second != (*it2).second) {
            tmp2.push_back((*it));
            tmp2.push_back((*it2));
          }
        }
      }
    }
    seg.clear();
    for (long long j = 0; j < tmp2.size(); j += 2) {
      auto it = st.find(tmp2[j]);
      if (it != st.end()) st.erase(it);
      it = st.find(tmp2[j + 1]);
      if (it != st.end()) st.erase(it);
      seg.push_back({tmp2[j].first, tmp2[j + 1].first});
    }
  }
  cout << ans << "\n";
}
