#include <bits/stdc++.h>
using namespace std;
int lleft[1000000];
int rright[1000000];
int col[1000000];
bool around[1000000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string in;
  cin >> in;
  int N = in.size();
  int alive = N;
  int count = 0;
  for (int i = 0; i < N; ++i) around[i] = true;
  if (N >= 2) rright[0] = 1;
  if (N >= 2) lleft[N - 1] = N - 2;
  for (int i = 1; i < N - 1; ++i) {
    lleft[i] = i - 1;
    rright[i] = i + 1;
  }
  lleft[0] = -1;
  rright[N - 1] = -1;
  for (int i = 0; i < N; ++i) col[i] = (int)(in[i] - 'a');
  queue<int> todo;
  for (int i = 0; i < N; ++i) todo.push(i);
  while (!todo.empty() && alive > 0) {
    queue<int> todel;
    while (!todo.empty()) {
      auto cur = todo.front();
      todo.pop();
      int l = lleft[cur];
      int r = rright[cur];
      if (around[cur]) {
        if ((l >= 0 && col[l] != col[cur]) || (r >= 0 && col[r] != col[cur])) {
          todel.push(cur);
        }
      }
    }
    bool k = false;
    while (!todel.empty()) {
      auto cur = todel.front();
      todel.pop();
      if (!around[cur]) continue;
      int l = lleft[cur];
      int r = rright[cur];
      if (l >= 0) {
        rright[l] = r;
        todo.push(l);
      }
      if (r >= 0) {
        lleft[r] = l;
        todo.push(r);
      }
      --alive;
      around[cur] = false;
      k = true;
    }
    if (k) ++count;
  }
  cout << count << endl;
}
