#include <bits/stdc++.h>
using namespace std;
struct st {
  int left;
  int right;
} T[1 << 20];
char s[1 << 20];
vector<pair<int, int> > v[2];
int ans;
int main() {
  scanf("%s", s);
  int n = strlen(s);
  s[n] = s[n - 1];
  for (int i = 0; i <= n - 1; i++) {
    T[i].left = i - 1;
    T[i].right = i + 1;
  }
  int t = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] != s[i - 1])
      t++;
    else {
      if (t != 0) v[0].push_back({i - t - 1, i - 1});
      t = 0;
    }
  }
  int hr = 0;
  while (!v[hr].empty()) {
    ans++;
    for (auto i : v[hr]) {
      int p = T[i.first].left;
      T[p].right = T[i.second].right;
      p = T[i.second].right;
      T[p].left = T[i.first].left;
      if (s[i.first] != s[i.second] && T[i.first].left != -1 &&
          T[i.second].right != n) {
        if (!v[!hr].empty() && v[!hr].back().second == T[i.first].left)
          v[!hr][v[!hr].size() - 1].second = T[i.second].right;
        else
          v[!hr].push_back({T[i.first].left, T[i.second].right});
      }
    }
    v[hr].clear();
    hr = !hr;
  }
  printf("%d", ans);
}
