#include <bits/stdc++.h>
using namespace std;
const int N = 2000006;
const int MOD = 1e9 + 7;
char in[N];
int main() {
  scanf("%s", in);
  int n = strlen(in);
  vector<pair<char, int> > vc;
  for (int i = 0; i < n; i++) {
    int ix = i;
    while (ix < n && in[ix] == in[i]) {
      ix++;
    }
    vc.push_back(make_pair(in[i], ix - i));
    i = ix - 1;
  }
  int res = 0;
  while (vc.size() >= 2) {
    vector<pair<char, int> > tc, cg;
    int best = 0x3f3f3f3f;
    for (auto i : vc) best = min(best, i.second);
    for (int i = 1; i + 1 < vc.size() && best > 1; i++) {
      best = min(best, vc[i].second / 2);
    }
    if (best == 0) best = 1;
    res += best;
    vc[0].second -= best;
    vc.back().second -= best;
    for (int i = 1; i + 1 < vc.size(); i++) {
      int mn = min(vc[i].second, best * 2);
      vc[i].second -= mn;
    }
    for (auto i : vc)
      if (i.second) tc.push_back(i);
    vc.clear();
    for (int i = 0; i < tc.size(); i++) {
      int ix = i;
      int c = 0;
      while (ix < tc.size() && tc[ix].first == tc[i].first) {
        c += tc[ix].second;
        ix++;
      }
      vc.push_back(make_pair(tc[i].first, c));
      i = ix - 1;
    }
  }
  printf("%d\n", res);
  return 0;
}
