#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 1e6 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
pair<long long, long long> a[MAX], b[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  long long t = 0, ans = 0, st = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s[st]) {
      t++;
      a[t] = {i - st, s[st] - 'a'};
      st = i;
    }
  }
  t++;
  a[t] = {s.size() - st, s[st] - 'a'};
  while (t > 1) {
    ans++;
    a[1].first--;
    a[t].first--;
    for (int i = 2; i < t; i++) a[i].first -= 2;
    long long la = 0, x = 0;
    for (int i = 1; i <= t; i++) {
      if (a[i].first > 0) {
        if (la != 0) {
          if (a[la].second == a[i].second)
            b[x].second += a[i].second;
          else {
            x++;
            b[x] = a[i];
            la = i;
          }
        } else {
          x = 1;
          b[1] = a[i];
          la = i;
        }
      }
    }
    t = x;
    for (int i = 1; i <= x; i++) a[i] = b[i];
  }
  if (t == 1) ans++;
  cout << ans;
  return 0;
}
