#include <bits/stdc++.h>
using namespace std;
bool used[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  string a;
  cin >> a;
  vector<pair<int, char> > V;
  int cnt = 1;
  for (int i = 1; i < a.length(); ++i) {
    if (a[i] == a[i - 1])
      cnt++;
    else {
      V.push_back(make_pair(cnt, a[i - 1]));
      cnt = 1;
    }
  }
  V.push_back(make_pair(cnt, a[a.length() - 1]));
  int d = 0;
  if ((int)V.size() == 1) {
    cout << 0;
    return 0;
  }
  while (true) {
    d++;
    V[0].first--;
    V[(int)V.size() - 1].first--;
    for (int i = 1; i < (int)V.size() - 1; ++i) {
      V[i].first -= 2;
    }
    int t = (int)V.size();
    for (int i = 0; i < (int)V.size(); ++i) {
      if (V[i].first <= 0) used[i] = true;
    }
    bool ok = true;
    vector<pair<int, char> > V2;
    for (int i = 0; i < t; ++i) {
      if (used[i] == false && ok == true) {
        ok = false;
        V2.push_back(V[i]);
      } else if (used[i] == false) {
        if (V2[(int)V2.size() - 1].second == V[i].second) {
          V2[(int)V2.size() - 1].first += V[i].first;
        } else {
          V2.push_back(V[i]);
        }
      }
      used[i] = false;
    }
    V = V2;
    if (ok == true || (int)V2.size() == 1) {
      cout << d;
      return 0;
    }
  }
  return 0;
}
