#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int INF = 1e18;
long long int po(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b % 2 == 1) {
      re = (re * a) % mod;
    }
    a = (a * a) / mod;
    b >>= 1;
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  while (test--) {
    string s;
    cin >> s;
    vector<vector<pair<char, int> > > dp;
    vector<pair<char, int> > k;
    dp.push_back(k);
    char p = '`';
    int l = -1, r = 0, ans = 0;
    bool f;
    for (int i = (0); i < (s.size()); i++) {
      if (s[i] == p) {
        dp[0][l].second++;
      } else {
        p = s[i];
        dp[0].push_back(make_pair(p, 1));
        l++;
      }
    }
    while (dp[r].size() > 1) {
      f = 1;
      while (f) {
        for (int i = (1); i < (dp[r].size()); i++) {
          dp[r][i].second--;
          dp[r][i - 1].second--;
          if (dp[r][i - 1].second < 1) {
            f = 0;
          }
        }
        if (dp[r][dp[r].size() - 1].second < 1) {
          f = 0;
        }
        ans++;
      }
      p = '`';
      dp.push_back(k);
      l = -1;
      for (int i = (0); i < (dp[r].size()); i++) {
        if (dp[r][i].second > 0) {
          if (dp[r][i].first == p)
            dp[r + 1][l].second += dp[r][i].second;
          else {
            p = dp[r][i].first;
            dp[r + 1].push_back(make_pair(p, dp[r][i].second));
            l++;
          }
        }
      }
      r++;
    }
    cout << ans;
  }
  return 0;
}
