#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
struct node {
  char c;
  int n;
} mp[MAXN];
int len;
void update() {
  int t = len;
  len = -1;
  for (int i = 0; i <= t; i++) {
    if (mp[i].n > 0) {
      if (len > -1 && mp[len].c == mp[i].c)
        mp[len].n += mp[i].n;
      else
        mp[++len] = mp[i];
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  string s;
  cin >> s;
  len = s.size() - 1;
  for (int i = 0; i <= len; i++) mp[i].c = s[i], mp[i].n = 1;
  update();
  int ans = 0;
  while (len > 0) {
    ans++;
    for (int i = 1; i < len; i++) mp[i].n -= 2;
    mp[0].n--;
    mp[len].n--;
    update();
  }
  cout << ans << endl;
  return 0;
}
