#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
char s[N];
vector<pair<char, int> > v;
void debug() {
  for (auto p : v) {
    cout << p.first << ' ' << p.second << '\n';
  }
  cout << "end debug\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  int i = 0;
  char last = 0;
  int count = 0;
  for (; s[i]; ++i) {
    if (s[i] == last) {
      count += 1;
    } else {
      if (last) v.push_back(make_pair(last, count));
      last = s[i];
      count = 1;
    }
  }
  if (last) v.push_back(make_pair(last, count));
  int ans = 0;
  while (v.size() > 1) {
    int min = N;
    for (int i = 0; i < v.size(); ++i) {
      if (v[i].second < min) min = v[i].second;
    }
    min = (min + 1) >> 1;
    for (int i = 0; i < v.size(); ++i) {
      if (i == 0 || i + 1 == v.size())
        v[i].second -= min;
      else
        v[i].second -= min << 1;
    }
    v.erase(remove_if(v.begin(), v.end(),
                      [](pair<char, int> p) { return p.second <= 0; }),
            v.end());
    char last = 0;
    int lasti = -1;
    for (int i = 0; i < v.size(); ++i) {
      if (v[i].first == last && v[i].second > 0) {
        v[lasti].second += v[i].second;
        v[i].second = -1;
      } else {
        last = v[i].first;
        lasti = i;
      }
    }
    v.erase(remove_if(v.begin(), v.end(),
                      [](pair<char, int> p) { return p.second <= 0; }),
            v.end());
    ans += min;
  }
  cout << ans;
}
