#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char>> v;
char str[(int)1e6 + 4], pre;
int ans, i, cnt, idx;
int main() {
  scanf("%s", str);
  pre = str[0];
  for (i = 0; str[i] != NULL; i++) {
    if (str[i] == pre)
      cnt++;
    else {
      v.push_back({cnt, str[i - 1]});
      cnt = 1;
      pre = str[i];
    }
  }
  v.push_back({cnt, str[i - 1]});
  while (v.size() > 1) {
    cnt = (int)1e6 + 4;
    for (i = 0; i < v.size(); i++) {
      if (i == 0 || i == v.size() - 1) {
        if (v[i].first < cnt) cnt = v[i].first;
      } else if ((v[i].first + 1) >> 1 < cnt)
        cnt = (v[i].first + 1) >> 1;
    }
    ans += cnt;
    for (int i = 0; i < v.size(); i++) {
      if (i == 0 || i == v.size() - 1)
        v[i].first -= cnt;
      else
        v[i].first -= cnt << 1;
      if (v[i].first < 1) {
        v.erase(v.begin() + i);
        i--;
      }
    }
    for (int i = 1; i < v.size(); i++) {
      if (v[i].second == v[i - 1].second) {
        v[i - 1].first += v[i].first;
        v.erase(v.begin() + i);
        i--;
      }
    }
  }
  printf("%d", ans);
}
