#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans, x, op, v[1000010], pr[1000010], nt[1000010];
vector<int> zh, fan;
char s[1000010];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) pr[i] = i - 1, nt[i] = i + 1;
  for (i = 1; i <= n; i++) {
    op = 0;
    if (i > 1 && s[i] != s[i - 1]) op = 1;
    if (i < n && s[i] != s[i + 1]) op = 1;
    if (op) zh.push_back(i), v[i] = 1;
  }
  while (zh.size()) {
    ans++;
    fan.clear();
    for (i = 0; i < zh.size(); i++) {
      x = zh[i];
      if (pr[x] && !v[pr[x]]) fan.push_back(pr[x]);
      if (nt[x] <= n && !v[nt[x]]) fan.push_back(nt[x]);
      if (pr[x]) nt[pr[x]] = nt[x];
      if (nt[x] <= n) pr[nt[x]] = pr[x];
    }
    zh.clear();
    for (i = 0; i < fan.size(); i++) {
      x = fan[i];
      if (v[x]) continue;
      op = 0;
      if (pr[x] && s[x] != s[pr[x]]) op = 1;
      if (nt[x] <= n && s[x] != s[nt[x]]) op = 1;
      if (op) zh.push_back(x), v[x] = 1;
    }
  }
  printf("%d", ans);
}
