#include <bits/stdc++.h>
using namespace std;
int input() {
  int res = 0;
  char c = ' ';
  while (c < '0') c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res;
}
const int N = 1e6 + 1;
int main() {
  set<int> d, v;
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); ++i)
    if (s[i] != s[i - 1]) d.insert(i);
  for (int i = 0; i < s.size(); ++i) v.insert(i);
  int ans = 0;
  while (d.size()) {
    for (int i : d) {
      if (v.count(i)) v.erase(i);
      if (v.count(i - 1)) v.erase(i - 1);
    }
    set<int> bf;
    for (int i : d) {
      auto it1 = v.lower_bound(i);
      if (it1 == v.end()) continue;
      if (it1 == v.begin()) continue;
      auto it2 = it1;
      --it2;
      int l = *it1, r = *it2;
      if (s[l] != s[r]) bf.insert(r);
    }
    d = bf;
    ++ans;
  }
  cout << ans;
}
