#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005;
struct Node {
  char c;
  long long x;
};
list<Node> l;
string s;
long long n;
signed main() {
  ios::sync_with_stdio(false);
  cin >> s;
  long long t_cnt = 0;
  n = s.length();
  for (long long i = 0; i < n; i++) {
    ++t_cnt;
    if (i == n - 1 || s[i] != s[i + 1]) {
      l.push_back({s[i], t_cnt});
      t_cnt = 0;
    }
  }
  long long flag = 1, last = 0, ans = 0;
  while (l.size() > 1) {
    ++ans;
    for (auto it = l.begin(); it != l.end(); it++) {
      it->x -= 2;
    }
    l.begin()->x++;
    l.rbegin()->x++;
    for (auto it = l.begin(); it != l.end(); it++) {
      if (it->x <= 0) it = l.erase(it), it--;
      if (it == l.end()) break;
    }
    for (auto it = l.begin(); it != l.end(); it++) {
      auto t_it = it;
      t_it++;
      if (t_it == l.end()) break;
      while (t_it->c == it->c) {
        it->x += t_it->x;
        t_it = l.erase(t_it);
        if (t_it == l.end()) break;
      }
    }
  }
  cout << ans << endl;
}
