#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p, long long md) {
  if (p == 0) return 1;
  if (p % 2 == 1) {
    return ((b % md) * bigmod(b, p - 1, md)) % md;
  } else {
    long long y = bigmod(b, p / 2, md);
    return (y * y) % md;
  }
}
int main() {
  string str;
  cin >> str;
  vector<long long> v;
  vector<char> cv;
  for (long long i = 0; i < str.size(); i++) {
    long long c = 0;
    long long j = i;
    while (j < str.size() && str[j] == str[i]) {
      c++;
      j++;
    }
    v.push_back(c);
    cv.push_back(str[i]);
    --j;
    i = j;
  }
  long long op = 0;
  while (1) {
    if (v.size() <= 1) break;
    vector<long long> tem_v;
    vector<char> tem_cv;
    for (long long i = 0; i < v.size(); i++) {
      long long bad = 2;
      if (i == 0 || i + 1 == v.size()) {
        bad = 1;
      }
      if (v[i] > bad) {
        if (tem_cv.size() && tem_cv.back() == cv[i]) {
          long long t = tem_v.back() + v[i] - bad;
          tem_v.pop_back();
          tem_v.push_back(t);
        } else {
          tem_v.push_back(v[i] - bad);
          tem_cv.push_back(cv[i]);
        }
      }
    }
    op++;
    v = tem_v;
    cv = tem_cv;
  }
  cout << op << "\n";
  return 0;
}
