#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v;
  string s;
  vector<char> color;
  cin >> s;
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      cnt++;
    } else {
      color.push_back(s[i - 1]);
      v.push_back(cnt);
      cnt = 1;
    }
  }
  if (v.size() == 0) {
    cout << 0 << endl;
    exit(0);
  }
  color.push_back(s[s.size() - 1]);
  v.push_back(cnt);
  long long ans = 0;
  while (1) {
    long long minn = v[0];
    minn = min(v[0], v[v.size() - 1]);
    for (int i = 1; i < v.size() - 1; i++) {
      if (v[i] % 2 == 1)
        minn = min((v[i] + 1) / 2, minn);
      else
        minn = min(v[i] / 2, minn);
    }
    if (minn == 0) minn = 1;
    v[0] -= minn;
    if (v.size() - 1 != 0) {
      v[v.size() - 1] -= minn;
    }
    ans += minn;
    for (int i = 1; i < v.size() - 1; i++)
      v[i] = max((long long)0, v[i] - minn * 2);
    long long gotoind[v.size()];
    for (int i = 0; i < v.size(); i++) gotoind[i] = i;
    long long ind = 0;
    for (int i = 0; i < v.size(); i++) {
      long long curr = i;
      while (i < v.size() && v[i] == 0) {
        if (i > 0)
          gotoind[i] = gotoind[i - 1];
        else
          gotoind[i] = 0;
        i++;
      }
      if (i < v.size()) {
        if (i == 18) {
        }
        if (curr > 0 && color[gotoind[curr - 1]] == color[i]) {
          v[gotoind[curr - 1]] += v[i];
          gotoind[i] = gotoind[curr - 1];
        } else {
          v[ind] = v[i];
          gotoind[i] = ind;
          color[ind] = color[i];
          ind++;
        }
      }
    }
    v.erase(v.begin() + ind, v.end());
    if (v.size() <= 1) break;
  }
  cout << ans << endl;
  return 0;
}
