#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
string s;
int n;
vector<pair<int, int> > v;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  n = ((int)s.size());
  int p = 0;
  for (int i = 0; i < (n); i++) {
    int t = i;
    while (t < n && s[p] == s[t]) t++;
    v.push_back(make_pair(s[p] - 'a', t - p));
    p = t;
  }
  int sp = 0;
  while (1) {
    if (((int)v.size()) <= 1) {
      cout << sp << "\n";
      break;
    }
    vector<pair<int, int> > tmp;
    for (int i = 0; i < (((int)v.size())); i++) {
      int a = v[i].first, b = v[i].second;
      if (!i || i + 1 == ((int)v.size())) {
        b--;
      } else
        b -= 2;
      if (b > 0) {
        if (((int)tmp.size()) && a == tmp.back().first)
          tmp.back().second += b;
        else
          tmp.push_back(make_pair(a, b));
      }
    }
    v = tmp;
    sp++;
  }
}
