#include <bits/stdc++.h>
using namespace std;
int len;
vector<pair<int, char>> grps;
int main() {
  std::ios::sync_with_stdio(false);
  ;
  string str;
  std::cin >> str;
  len = str.length();
  str.push_back('!');
  for (int i = 0; i < len;) {
    int ct = 0;
    while (str[i] == str[i + 1]) {
      ct++;
      i++;
    }
    ct++;
    grps.push_back(make_pair(ct, str[i]));
    i++;
  }
  int tot = 0;
  int sz = grps.size();
  while (sz > 1) {
    vector<pair<int, char>> gp2;
    int mi = 100000000;
    int ct2 = 0;
    for (int i = 0; i < sz; i++) {
      if (i == 0 || i == sz - 1) {
        mi = min(mi, grps[i].first);
      } else {
        mi = min(mi, (grps[i].first / 2) + (grps[i].first % 2));
      }
    }
    tot += mi;
    for (int i = 0; i < sz; i++) {
      if (i == 0 || i == sz - 1) {
        if (mi < grps[i].first) {
          if (i == sz - 1) {
            if (ct2) {
              if (grps[i].second == gp2[ct2 - 1].second) {
                gp2[ct2 - 1].first += (grps[i].first - mi);
              }
            } else
              gp2.push_back(make_pair(grps[i].first - mi, grps[i].second)),
                  ct2++;
          } else {
            gp2.push_back(make_pair(grps[i].first - mi, grps[i].second)), ct2++;
          }
        }
      } else {
        if (2 * mi < grps[i].first) {
          if (ct2) {
            if (grps[i].second == gp2[ct2 - 1].second) {
              gp2[ct2 - 1].first += (grps[i].first - 2 * mi);
            }
          } else
            gp2.push_back(make_pair(grps[i].first - 2 * mi, grps[i].second)),
                ct2++;
        }
      }
    }
    swap(grps, gp2);
    sz = ct2;
  }
  std::cout << tot << endl;
  return 0;
}
