#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MAX = 1e6 + 20;
long long inf = (long long)1e9;
long long mod = (long long)1e9 + 7;
long long n, k, pref[MAX], t = 0;
set<pair<long long, pair<long long, long long>>> vals;
string s;
void solve() {
  cin >> s;
  long long curnum = 0, curh = s[0] - 97;
  for (int i = 0; i < s.size(); i++) {
    if (i && s[i] != s[i - 1]) {
      t++;
      vals.insert({t, {curnum, curh}});
      curnum = 1;
      curh = s[i] - 97;
    } else
      curnum++;
  }
  if (curnum) {
    t++;
    vals.insert({t, {curnum, curh}});
  }
  long long ans = 0;
  while (vals.size() > 1) {
    ans++;
    vector<pair<long long, pair<long long, long long>>> del, temp;
    for (auto u : vals) del.push_back(u);
    vals.clear();
    del[0].second.first--;
    del.back().second.first--;
    for (int i = 1; i < del.size() - 1; i++) {
      del[i].second.first -= 2;
    }
    for (int i = 0; i < del.size(); i++) {
      if (del[i].second.first > 0) {
        temp.push_back(del[i]);
      }
    }
    if (temp.size()) {
      t = 0;
      curnum = temp[0].second.first, curh = temp[0].second.second;
      for (int i = 1; i < temp.size(); i++) {
        if (temp[i].second.second != curh) {
          t++;
          vals.insert({t, {curnum, curh}});
          curnum = temp[i].second.first;
          curh = temp[i].second.second;
        } else
          curnum += temp[i].second.first;
      }
      t++;
      vals.insert({t, {curnum, curh}});
    }
  }
  cout << ans;
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  ios::sync_with_stdio(0);
  long long q;
  q = 1;
  while (q--) solve();
  return 0;
}
