#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int ans(0);
bool go(vector<pair<char, int> > &a, vector<pair<char, int> > &b) {
  b.clear();
  int mn = INF;
  for (int i(0); i < a.size(); i++) {
    if (i == 0 || i == a.size() - 1) {
      mn = min(mn, a[i].second);
    } else {
      mn = min(mn, a[i].second / 2 + (a[i].second & 1));
    }
  }
  bool f(0);
  for (int i(0); i < a.size(); i++) {
    if (i != a.size() - 1) {
      a[i].second -= mn;
      a[i + 1].second -= mn;
    }
    if (a[i].second <= 0) {
      f = 1;
    } else {
      if (b.size() && b[b.size() - 1].first == a[i].first) {
        b[b.size() - 1].second += a[i].second;
      } else
        b.push_back(a[i]);
    }
  }
  if (a.size() == 1) return 0;
  if (f) ans += mn;
  return f;
}
int main() {
  string s;
  cin >> s;
  vector<pair<char, int> > a;
  vector<pair<char, int> > b;
  char last = s[0];
  a.push_back({last, 1});
  for (int i(1); i < s.size(); i++) {
    if (s[i] == last) {
      a[a.size() - 1].second++;
    } else {
      last = s[i];
      a.push_back({last, 1});
    }
  }
  int iter = 0;
  while (1) {
    bool f = 0;
    if (iter & 1) {
      f = (go(b, a));
    } else {
      f = go(a, b);
    }
    iter++;
    if (!f) break;
  }
  cout << ans;
  return 0;
}
