#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
struct group {
  int sz;
  char c;
};
int solve(vector<group> arr) {
  if ((int)arr.size() <= 1) return 0;
  vector<group> narr;
  for (int i = 0; i < (int)arr.size(); i++) {
    if (i) arr[i].sz--;
    if (i != (int)arr.size() - 1) arr[i].sz--;
  }
  for (int i = 0; i < (int)arr.size(); i++) {
    if (arr[i].sz > 0) narr.push_back(arr[i]);
  }
  if ((int)narr.size() == 0) return 1;
  vector<group> res;
  char prev = narr[0].c;
  int ind = 0;
  group cur = {0, narr[0].c};
  while (ind != (int)narr.size()) {
    while (ind != (int)narr.size() && narr[ind].c == prev) {
      cur.sz += narr[ind].sz;
      ind++;
    }
    res.push_back(cur);
    if (ind != (int)narr.size()) {
      cur.sz = 0;
      cur.c = narr[ind].c;
      prev = narr[ind].c;
    }
  }
  return 1 + solve(res);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  vector<group> arr;
  group cur = {0, s[0]};
  char prev = s[0];
  int n = (int)s.size();
  int ind = 0;
  while (ind != n) {
    while (ind != n && prev == s[ind]) {
      ind++;
      cur.sz++;
    }
    arr.push_back(cur);
    if (ind != n) {
      cur.sz = 0;
      cur.c = s[ind];
      prev = s[ind];
    }
  }
  cout << solve(arr);
  return 0;
}
