#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
pair<int, int> stk[2][N];
int stop[2];
void push(pair<int, int> x, int idx) {
  int& _stop = stop[idx];
  if (_stop == 0 || x.first != stk[idx][_stop - 1].first) {
    stk[idx][_stop++] = x;
  } else {
    stk[idx][_stop - 1].second += x.second;
  }
}
int main() {
  string buf;
  cin >> buf;
  int f = 0;
  for (int i = 0; i < (int)buf.size(); i++) {
    pair<int, int> now = make_pair(buf[i] - 'a', 1);
    push(now, f);
  }
  int res = 0;
  while (stop[f] > 1) {
    f = 1 - f;
    res++;
    stop[f] = 0;
    for (int i = 0; i < stop[1 - f]; i++) {
      pair<int, int>& now = stk[1 - f][i];
      if (i == 0 || i == stop[1 - f] - 1) {
        if (now.second > 1) {
          now.second--;
          push(now, f);
        }
      } else {
        if (now.second > 2) {
          now.second -= 2;
          push(now, f);
        }
      }
    }
  }
  cout << res << endl;
}
