#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) {
        if (!v[0].empty() && v[0].back().second == i - t - 2)
          v[0][v[0].size() - 1].second = i - 1;
        else
          v[0].push_back({i - t - 1, i - 1});
      }
      t = 0;
    }
  }
  int hr = 0;
  while (!v[hr].empty()) {
    ans++;
    for (auto i : v[hr]) {
      if (i.first == -2) continue;
      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});
      }
    }
    for (int i = 0; i < v[!hr].size(); i++) {
      if (T[v[!hr][i].first].left == v[!hr][i - 1].second)
        v[!hr][i].first = v[!hr][i - 1].first, v[!hr][i - 1].first = -2;
    }
    v[hr].clear();
    hr = !hr;
  }
  printf("%d", ans);
}
