#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, k, i, j, maxi = 1, ans = 0;
  int start = 0, end;
  string s, s2;
  cin >> s;
  vector<int> v;
  multiset<pair<int, int> > ms1;
  multiset<pair<int, int> >::iterator it;
  v.push_back(1);
  s2 += s[0];
  for (i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1])
      v.back()++;
    else {
      ms1.insert({v.back(), v.size() - 1});
      maxi = max(maxi, v.back());
      v.push_back(1);
      s2 += s[i];
    }
  }
  s = s2;
  maxi = max(maxi, v.back());
  ms1.insert({v.back(), v.size() - 1});
  n = v.size();
  end = n - 1;
  int next[n], prev[n], offset = 0;
  for (i = 0; i < n - 1; i++) {
    next[i] = i + 1;
    prev[n - i - 1] = n - i - 2;
  }
  next[i] = -1;
  prev[n - i - 1] = -1;
  if (maxi % 2) maxi++;
  offset += 2;
  ans++;
  while (ms1.size() > 1) {
    if (start != end) {
      ms1.erase({v[start], start});
      ms1.erase({v[end], end});
      v[start]++;
      v[end]++;
      ms1.insert({v[start], start});
      ms1.insert({v[end], end});
    }
    it = ms1.begin();
    while (ms1.size() > 1 && it->first <= offset) {
      j = it->second;
      if (j == start) start = next[j];
      if (j == end) end = prev[j];
      if (prev[j] != -1) next[prev[j]] = next[j];
      if (next[j] != -1) prev[next[j]] = prev[j];
      ms1.erase({v[j], j});
      while (ms1.size() > 1 && next[j] != -1 && prev[j] != -1 &&
             s2[next[j]] == s2[prev[j]]) {
        j = next[j];
        if (j == start) start = next[j];
        if (j == end) end = prev[j];
        if (prev[j] != -1) {
          ms1.erase({v[prev[j]], prev[j]});
          v[prev[j]] += v[j] - offset;
          ms1.insert({v[prev[j]], prev[j]});
          next[prev[j]] = next[j];
        }
        if (next[j] != -1) prev[next[j]] = prev[j];
        ms1.erase({v[j], j});
      }
      it = it = ms1.begin();
    }
    offset += 2;
    ans++;
  }
  cout << ans - 1;
  return 0;
}
