#include <bits/stdc++.h>
using namespace std;
int n;
list<pair<int, int> > vs;
string str;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> str;
  n = str.length();
  for (int i = 0, j = 0; i < n; i = j) {
    while (j < n && str[i] == str[j]) j++;
    vs.push_back((make_pair((i), (j - i))));
  }
  int res = 0;
  while (vs.size() > 1) {
    int mi = 2147483647;
    for (auto it = vs.begin(), nit = vs.begin(); it != vs.end(); it = nit) {
      nit++;
      if (it == vs.begin() || nit == vs.end())
        mi = min(it->second, mi);
      else
        mi = min((it->second + 1) / 2, mi);
    }
    res += mi;
    for (auto &x : vs) x.second -= mi * 2;
    vs.front().second += mi;
    vs.back().second += mi;
    for (auto it = vs.begin(), nit = vs.begin(); it != vs.end(); it = nit) {
      nit++;
      if (it->second <= 0) vs.erase(it);
    }
    for (auto it = vs.begin(); it != vs.end(); it++) {
      for (auto nit = it; ++nit != vs.end(); nit = it) {
        if (str[it->first] == str[nit->first]) {
          it->second += nit->second;
          vs.erase(nit);
        } else
          break;
      }
    }
  }
  cout << res << endl;
  return 0;
}
