#include <bits/stdc++.h>
using namespace std;
char s[1000005];
vector<pair<int, char> > v;
int main() {
  scanf("%s", s);
  char c = s[0];
  int cnt = 0;
  for (int i = 0; i <= strlen(s); i++) {
    if (i == strlen(s) || s[i] != c) {
      v.push_back(pair<int, char>(cnt, c));
      cnt = 1;
      c = s[i];
    } else
      cnt++;
  }
  int ans = 0;
  while (v.size() > 1) {
    ans++;
    int m = v[0].first;
    for (int i = 1; i < v.size() - 1; i++) m = min(m, v[i].first / 2);
    m = min(m, v[v.size() - 1].first);
    v[0].first -= m;
    for (int i = 1; i < v.size() - 1; i++) v[i].first -= m * 2;
    v[v.size() - 1].first -= m;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].first <= 0) {
        v.erase(v.begin() + i);
        i--;
      }
    }
    for (int i = 1; i < v.size(); i++) {
      if (v[i - 1].second == v[i].second) {
        v[i - 1].first += v[i].first;
        v.erase(v.begin() + i);
        i--;
      }
    }
  }
  printf("%d", ans);
  return 0;
}
