#include <bits/stdc++.h>
using namespace std;
string s;
vector<pair<char, int> > v, tmp;
int main() {
  cin >> s;
  int len = s.length();
  v.push_back(pair<int, int>(s[0], 1));
  for (int i = 1; i < len; i++) {
    if (s[i] == v.back().first) {
      v[v.size() - 1].second++;
    } else {
      v.push_back(pair<int, int>(s[i], 1));
    }
  }
  int ans = 0;
  while (v.size() > 1) {
    ans++;
    for (int i = 0; i < v.size(); i++) {
      if (!i) {
        if (v[i].second - 1 > 0) {
          v[i].second--;
          tmp.push_back(v[i]);
        }
      } else if (i == v.size() - 1) {
        if (v[i].second - 1 > 0) {
          v[i].second--;
          if (!tmp.empty() && tmp.back().first == v[i].first) {
            tmp[tmp.size() - 1].second++;
          } else {
            tmp.push_back(v[i]);
          }
        }
      } else {
        if (v[i].second - 2 > 0) {
          v[i].second -= 2;
          if (!tmp.empty() && tmp.back().first == v[i].first) {
            tmp[tmp.size() - 1].second++;
          } else {
            tmp.push_back(v[i]);
          }
        }
      }
    }
    v = tmp;
    tmp.clear();
  }
  cout << ans << endl;
  return 0;
}
