#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
struct comp {
  char c;
  int cnt;
  comp(char c, int cnt) : c(c), cnt(cnt) {}
};
int n;
string s;
vector<comp> ve;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  n = s.length();
  int i = 0;
  while (i < n) {
    int j = i;
    while (j < n && s[i] == s[j]) j++;
    ve.emplace_back(s[i], j - i);
    i = j;
  }
  int it = 0;
  while (((int)(ve).size()) > 1) {
    int k = ((int)(ve).size());
    for (int i = (0); i < (k - 1); i++) {
      ve[i].cnt--;
      ve[i + 1].cnt--;
    }
    vector<comp> v2;
    for (int i = (0); i < (k); i++) {
      if (ve[i].cnt <= 0) continue;
      if (v2.empty() || v2.back().c != ve[i].c) {
        v2.push_back(ve[i]);
      } else {
        v2.back().cnt += ve[i].cnt;
      }
    }
    ve = v2;
    it++;
  }
  cout << it << '\n';
}
