#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  vector<pair<char, int>> A;
  int i = 0, n = s.size();
  while (i < n) {
    int j = i;
    while (j < n && s[i] == s[j]) {
      ++j;
    }
    A.push_back({s[i], j - i});
    i = j;
  }
  int stp = 0;
  while (A.size() > 1) {
    vector<pair<char, int>> B;
    ++stp;
    for (int i = 0; i < (int)A.size(); ++i) {
      if (i == 0 || i == (int)A.size() - 1) {
        A[i].second--;
      } else {
        A[i].second -= 2;
      }
      if (A[i].second > 0) {
        if (!B.empty() && B.back().first == A[i].first) {
          B.back().second += A[i].second;
        } else {
          B.push_back(A[i]);
        }
      }
    }
    A = B;
  }
  cout << stp << "\n";
  return 0;
}
