#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct node {
  int num, id;
  node(int a = 0, int b = 0) : num(a), id(b) {}
} p[maxn];
int main() {
  string str;
  cin >> str;
  int siz = 1, cnt = 0;
  for (int i = 1; i < str.size(); i++) {
    if (str[i] != str[i - 1]) {
      p[cnt].num = siz;
      p[cnt++].id = str[i - 1] - 'a';
      siz = 1;
    } else
      siz++;
    if (i == str.size() - 1) {
      p[cnt] = siz;
      p[cnt++].id = str[i] - 'a';
    }
  }
  int ans = 0;
  while (1) {
    p[0].num -= 1;
    p[cnt - 1].num -= 1;
    for (int i = 1; i <= cnt - 2; i++) p[i].num -= 2;
    int sta = 0;
    while (p[sta].num <= 0) sta++;
    int cal = 0;
    if (sta < cnt) {
      cal = 1;
      p[0] = p[sta];
    }
    for (int i = sta + 1; i < cnt; i++) {
      if (p[i].num <= 0)
        continue;
      else {
        if (p[i].id == p[cal - 1].id)
          p[cal - 1].num += p[i].num;
        else
          p[cal++] = p[i];
      }
    }
    ans++;
    cnt = cal;
    if (cnt <= 1) break;
  }
  cout << ans << endl;
  return 0;
}
