#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 5000 + 10;
int n;
int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  n = s.length();
  s = "#" + s;
  vector<pair<char, int> > v, vc;
  for (int i = 1; i <= n;) {
    int j = i;
    while (j <= n && s[j] == s[i]) j++;
    v.push_back({s[i], j - i});
    i = j;
  }
  int ans = 0;
  while ((int)v.size() > 1) {
    int sz = v.size();
    for (int i = 0; i < sz; i++) {
      if (i == 0 || i == sz - 1)
        v[i].second -= 1;
      else
        v[i].second -= 2;
    }
    vc.clear();
    for (int i = 0; i < sz; i++) {
      if (v[i].second <= 0) continue;
      if (!vc.empty() && vc.back().first == v[i].first)
        vc.back().second += v[i].second;
      else
        vc.push_back(v[i]);
    }
    v = vc;
    ans++;
  }
  cout << ans;
  return 0;
}
