#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string st;
  cin >> st;
  vector<pair<char, int>> cpv, tmp;
  int i = 1, j = 0, cnt = 0;
  while (i < st.size()) {
    if (st[i] != st[i - 1]) {
      cpv.push_back({st[i - 1], i - j});
      j = i;
    }
    i++;
  }
  cpv.push_back({st[i - 1], i - j});
  while (cpv.size() > 1) {
    i = 0;
    while (i < cpv.size()) {
      if (i == 0 || i == cpv.size() - 1)
        cpv[i].second--;
      else
        cpv[i].second -= 2;
      cpv[i].second = max(cpv[i].second, 0);
      i++;
    }
    tmp.clear();
    for (auto ey : cpv) {
      if (ey.second) {
        if (tmp.size() && tmp.back().first == ey.first)
          tmp.back().second += ey.second;
        else
          tmp.push_back(ey);
      }
    }
    swap(cpv, tmp);
    cnt++;
  }
  cout << cnt << "\n";
  return 0;
}
