#include <bits/stdc++.h>
using namespace std;
const int N = 5500, M = 350;
mt19937 gen(time(NULL));
template <typename T = int>
inline T read() {
  T val = 0, sign = 1;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') sign = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) val = val * 10 + ch - '0';
  return sign * val;
}
const int mod = 1e9 + 7;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  int len = 0;
  char curr = '.';
  vector<pair<int, char>> vu;
  for (int i = 0; i < n; i++) {
    if (curr != s[i]) {
      if (curr != '.') vu.push_back(make_pair(len, curr));
      curr = s[i];
      len = 0;
    }
    len++;
  }
  if (len) vu.push_back(make_pair(len, curr));
  int total = n;
  int its = 0;
  while (vu.size() > 1) {
    its++;
    int cut = 0;
    vector<pair<int, char>> ers;
    for (int i = 0; i < vu.size(); i++) {
      auto &v = vu[i];
      if (i > 0 && i < vu.size() - 1) {
        cut += min(2, v.first);
        if (v.first > 2) ers.push_back(make_pair(v.first - 2, v.second));
      } else {
        cut += min(1, v.first);
        if (v.first > 1) ers.push_back(make_pair(v.first - 1, v.second));
      }
    }
    vu.clear();
    int len = 0;
    char curr = '.';
    for (auto v : ers) {
      if (curr != v.second) {
        if (curr != '.') vu.push_back(make_pair(len, curr));
        curr = v.second;
        len = 0;
      }
      len += v.first;
    }
    if (len) vu.push_back(make_pair(len, curr));
  }
  printf("%d\n", its);
}
signed main() {
  int t = 1;
  while (t--) {
    clock_t z = clock();
    solve();
    fprintf(stderr, "Total Time: %.3f\n",
            (double)(clock() - z) / CLOCKS_PER_SEC),
        fflush(stderr);
  }
}
