#include <bits/stdc++.h>
using namespace std;
char sT[100005 * 10];
int main() {
  scanf("%s", sT + 1);
  sT[0] = sT[1];
  int n = strlen(sT) - 1;
  vector<pair<int, char> > vt;
  int cnt = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (sT[i] == sT[i - 1])
      cnt++;
    else {
      vt.push_back({cnt, sT[i - 1]});
      cnt = 1;
    }
  }
  int ans = 0;
  while (vt.size() > 1) {
    ans++;
    auto now = vt;
    now.clear();
    if (vt[0].first > 1) now.push_back({vt[0].first - 1, vt[0].second});
    for (int i = 1; i < vt.size() - 1; i++)
      if (vt[i].first > 2) now.push_back({vt[i].first - 2, vt[i].second});
    if (vt.back().first > 1)
      now.push_back({vt.back().first - 1, vt.back().second});
    vt.clear();
    if (now.empty()) break;
    vt.push_back(now[0]);
    for (int i = 1; i < now.size(); i++) {
      if (now[i].second == vt.back().second) {
        vt.back().first += now[i].first;
      } else {
        vt.push_back(now[i]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
