#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char s[N];
int n, m, ans, suf[N], pre[N];
bool D[N];
vector<int> del, rd;
void DEL(int x) {
  suf[pre[x]] = suf[x];
  pre[suf[x]] = pre[x];
}
bool check(int x) {
  if (pre[x] && s[pre[x]] != s[x]) return 1;
  if (suf[x] != n + 1 && s[suf[x]] != s[x]) return 1;
  return 0;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) pre[i] = i - 1, suf[i] = i + 1;
  pre[n + 1] = n;
  suf[0] = 1;
  for (int i = 1; i <= n; ++i)
    if (check(i)) del.push_back(i);
  while (del.size()) {
    ++ans;
    for (int i = 0; i < del.size(); ++i) D[del[i]] = 1;
    for (int i = 0; i < del.size(); ++i) {
      if (pre[del[i]] && !D[pre[del[i]]]) rd.push_back(pre[del[i]]);
      if (suf[del[i]] != n + 1 && !D[suf[del[i]]]) rd.push_back(suf[del[i]]);
    }
    for (int i = 0; i < del.size(); ++i) DEL(del[i]);
    del.clear();
    for (int i = 0; i < rd.size(); ++i)
      if (check(rd[i]) &&
          (!del.size() || (del.size() && del[del.size() - 1] != rd[i])))
        del.push_back(rd[i]);
    rd.clear();
  }
  printf("%d\n", ans);
  return 0;
}
