#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
char str[maxn];
int l[maxn], r[maxn], len, cnt = 0;
bool vis[maxn];
vector<int> del, chan;
bool check(int i) {
  if ((l[i] != -1 && str[i] != str[l[i]]) ||
      (r[i] < len && str[i] != str[r[i]]))
    return true;
  else
    return false;
}
void dele(int i) {
  r[l[i]] = r[i];
  l[r[i]] = l[i];
}
int main() {
  scanf("%s", str);
  len = strlen(str);
  for (int i = 0; i < len; i++) {
    l[i] = i - 1, r[i] = i + 1;
    if (check(i)) del.push_back(i), vis[i] = true;
  }
  while (del.size()) {
    cnt++;
    for (int i = 0; i < del.size(); i++)
      chan.push_back(l[del[i]]), chan.push_back(r[del[i]]), dele(del[i]);
    del.clear();
    for (int i = 0; i < chan.size(); i++) {
      if (chan[i] != -1 && chan[i] != len && !vis[chan[i]]) {
        if (check(chan[i])) vis[chan[i]] = true, del.push_back(chan[i]);
      }
    }
    chan.clear();
  }
  printf("%d\n", cnt);
  return 0;
}
