#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct node {
  char ch;
  int size;
  node() { size = 0; }
};
char s[maxn];
vector<node> v[2];
int main() {
  scanf("%s", s);
  int n = strlen(s), now = 0, pre = 1, MIN = INF, ans = 0;
  node u;
  u.size = 1;
  u.ch = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      v[now].push_back(u);
      u.size = 1;
      u.ch = s[i];
    } else {
      u.size++;
    }
  }
  v[now].push_back(u);
  int l = v[now].size();
  while (l > 1) {
    swap(now, pre);
    v[now].clear();
    MIN = INF;
    for (int i = 0; i < l; i++) {
      if (i == 0 || i == l - 1)
        MIN = min(MIN, v[pre][i].size);
      else
        MIN = min(MIN, (v[pre][i].size + 1) / 2);
    }
    ans += MIN;
    for (int i = 0; i < l; i++) {
      if (((i == 0 || i == l - 1) && v[pre][i].size > MIN) ||
          ((i > 0 && i < l - 1) && v[pre][i].size > 2 * MIN)) {
        if (i == 0 || i == l - 1)
          v[pre][i].size -= MIN;
        else
          v[pre][i].size -= 2 * MIN;
        if (v[now].size()) {
          if (v[now][v[now].size() - 1].ch == v[pre][i].ch) {
            v[now][v[now].size() - 1].size += v[pre][i].size;
          } else
            v[now].push_back(v[pre][i]);
        } else
          v[now].push_back(v[pre][i]);
      }
    }
    l = v[now].size();
  }
  printf("%d\n", ans);
  return 0;
}
