#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MIN;
long long mini = LLONG_MAX;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INFll = 1ll * 1000000000 * 1000000000;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
long long t, i, j, k, n, temp, flag, ans, m;
int main() {
  string s;
  cin >> s;
  vector<pair<long long, long long> > v;
  n = s.length();
  for (i = 0; i < n; i++) {
    long long c = 1;
    while (i < n && s[i] == s[i + 1]) {
      c++;
      i++;
    }
    v.push_back(make_pair(s[i], c));
  }
  while (v.size() >= 2) {
    ans++;
    std::vector<pair<long long, long long> > u;
    for (i = 0; i < v.size(); i++) {
      if (i == 0 || i == v.size() - 1)
        v[i].second--;
      else
        v[i].second = max(0LL, v[i].second - 2);
      if (v[i].second != 0) {
        if (u.size() == 0)
          u.push_back(v[i]);
        else if (u[u.size() - 1].first == v[i].first) {
          u[u.size() - 1].second += v[i].second;
        } else {
          u.push_back(v[i]);
        }
      }
    }
    v = u;
  }
  cout << ans;
  return 0;
}
