#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e6 + 5;
const long double pi = 3.14159265359;
const long long INF = (1LL << 63);
long long l, r, ans, cnt[N];
string s;
vector<pair<long long, long long> > v, tv;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  for (long long i = 0; i < (long long)s.size() - 1; i++) {
    if (s[i] != s[i + 1]) v.push_back(make_pair(i, i + 1));
  }
  if ((long long)v.size() == 0) {
    cout << "0\n";
    return 0;
  }
  while (1) {
    ans++;
    tv = v;
    v.clear();
    for (long long i = 0; i < (long long)tv.size(); i++) {
      l = tv[i].first, r = tv[i].second;
      cnt[l] = 1, cnt[r] = 1;
      while (i + 1 < (long long)tv.size() && tv[i + 1].first <= r) {
        i++;
        r = tv[i].second;
        cnt[r] = 1;
      }
      if (l - 1 < 0 || r + 1 >= (long long)s.size() || cnt[l - 1] || cnt[r + 1])
        continue;
      if (s[l - 1] != s[r + 1]) v.push_back(make_pair(l - 1, r + 1));
    }
    if ((long long)v.size() == 0) break;
  }
  cout << ans << "\n";
  return 0;
}
