#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000010];
struct Node {
  int s = 0;
  char c;
} t[1000010];
int cnt;
int main() {
  cin >> (a + 1);
  n = strlen(a + 1);
  t[0].c = '/';
  cnt = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] == t[cnt].c)
      t[cnt].s++;
    else
      t[++cnt].s = 1;
    t[cnt].c = a[i];
  }
  int ans = 0;
  while (cnt > 1) {
    ans++;
    for (int i = 1; i <= cnt; i++) {
      if (i == 1 || i == cnt)
        t[i].s -= 1;
      else
        t[i].s -= 2;
    }
    int cnt_ = 0;
    for (int i = 1; i <= cnt; i++) {
      if (t[i].s <= 0) continue;
      if (t[cnt_].c == t[i].c)
        t[cnt_].s += t[i].s;
      else
        t[++cnt_].s = t[i].s;
      t[cnt_].c = t[i].c;
    }
    cnt = cnt_;
  }
  cout << ans << "\n";
  return 0;
}
