#include <bits/stdc++.h>
using namespace std;
struct node {
  int color;
  int len;
  node(int _color, int _len) : color(_color), len(_len) {}
};
char s[1000005];
list<node> ls;
int maintain() {
  int res = INT_MAX;
  for (auto it = ls.begin(); it != ls.end(); ++it) {
    if (it == ls.begin() || it == prev(ls.end()))
      res = min(res, it->len);
    else
      res = min(res, it->len / 2 + it->len % 2);
  }
  for (auto it = ls.begin(); it != ls.end();) {
    if (it == ls.begin() || it == prev(ls.end()))
      it->len -= res;
    else
      it->len -= res * 2;
    if (it->len <= 0)
      it = ls.erase(it);
    else
      ++it;
  }
  if (ls.size() >= 1) {
    for (auto it = next(ls.begin()); it != ls.end();) {
      auto pre = prev(it);
      if (it->color == pre->color) {
        pre->len += it->len;
        it = ls.erase(it);
      } else
        ++it;
    }
  }
  return res;
}
int main(int argc, char* argv[]) {
  scanf("%s", s);
  for (int i = 0; s[i];) {
    int j;
    for (j = i; s[j] == s[i]; ++j)
      ;
    ls.emplace_back(s[i], j - i);
    i = j;
  }
  int res = 0;
  while (ls.size() > 1) res += maintain();
  printf("%d\n", res);
  return 0;
}
