#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e6 + 7;
int n;
char a[N];
set<int> s, rem;
int get_pv(set<int> &e, int x) {
  auto it = e.lower_bound(x);
  if (it == begin(e)) {
    return -1;
  }
  return *(--it);
}
int get_nxt(set<int> &e, int x) {
  auto it = e.lower_bound(x);
  if (it == end(e)) {
    return -1;
  }
  return *it;
}
int main() {
  scanf("%s", a);
  n = strlen(a);
  for (int i = 0; i < n; ++i) {
    rem.insert(i);
  }
  for (int i = 0; i < n; ++i) {
    if (i && a[i - 1] != a[i]) {
      s.insert(i - 1);
      s.insert(i);
    }
  }
  int ans = 0;
  while (!s.empty()) {
    ++ans;
    for (int i : s) {
      rem.erase(i);
    }
    vector<int> nxt;
    for (int i : s) {
      int fi = get_pv(rem, i);
      int se = get_nxt(rem, i);
      if (fi != -1 && se != -1 && a[fi] != a[se]) {
        nxt.push_back(fi);
        nxt.push_back(se);
      }
    }
    s.clear();
    for (int i : nxt) {
      s.insert(i);
    }
  }
  printf("%d\n", ans);
  return 0;
}
