#include <bits/stdc++.h>
using namespace std;
char str[1000007];
int l[1000007];
int r[1000007];
int main() {
  scanf("%s", str + 1);
  str[0] = str[1];
  int ln = strlen(str) - 1;
  for (int i = 1; i <= ln + 1; i++) l[i] = i - 1;
  for (int i = 0; i <= ln; i++) r[i] = i + 1;
  str[ln + 1] = str[ln];
  vector<int> rmv;
  for (int i = 1; i <= ln; i++) {
    if (str[i] != str[i - 1] or str[i] != str[i + 1]) rmv.push_back(i);
  }
  int ans = 0;
  while (!rmv.empty()) {
    ans++;
    int m = rmv.size();
    set<int> changed;
    int L, R;
    for (int i = 0; i < m; i++) {
      L = l[rmv[i]];
      for (i++; i < m and l[rmv[i]] == rmv[i - 1]; i++)
        ;
      i--;
      R = r[rmv[i]];
      l[R] = L;
      r[L] = R;
      if (L) changed.insert(L);
      if (R <= ln) changed.insert(R);
    }
    rmv.clear();
    for (int x : changed) {
      if (str[x] != str[l[x]] || str[x] != str[r[x]]) rmv.push_back(x);
    }
  }
  printf("%d\n", ans);
  return 0;
}
