#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, MOD - 2); }
const int N = 1e5 + 5;
string s;
vector<pair<char, int> > v, vv;
map<char, int> mpp;
int ans;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++) {
    if (mpp.find(s[i]) != mpp.end() or i == 0) {
      mpp[s[i]]++;
    } else {
      map<char, int>::iterator it = mpp.begin();
      char ch = it->first;
      int cnt = it->second;
      v.push_back(make_pair(ch, cnt));
      mpp.clear();
      mpp[s[i]]++;
    }
  }
  if ((int)mpp.size()) {
    map<char, int>::iterator it = mpp.begin();
    char ch = it->first;
    int cnt = it->second;
    v.push_back(make_pair(ch, cnt));
    mpp.clear();
  }
  while ((int)v.size() > 1) {
    ++ans;
    for (int i = 0; i < (int)v.size(); i++) {
      if (i == 0 or i == (int)v.size() - 1)
        v[i].second -= 1;
      else
        v[i].second -= 2;
    }
    vv.clear();
    for (int i = 0; i < (int)v.size(); i++) {
      if (v[i].second <= 0) continue;
      if ((int)vv.size() and vv.back().first == v[i].first)
        vv[(int)vv.size() - 1].second += v[i].second;
      else
        vv.push_back(make_pair(v[i].first, v[i].second));
    }
    v.clear();
    v = vv;
  }
  cout << ans;
}
