#include <bits/stdc++.h>
const long long MX = 100 * 10000 + 1000, inf = 0x7FFFFFFF,
                mod = 1000 * 1000 * 1000 + 7;
using namespace std;
struct linklist {
  long long l, r, c;
} inp[MX];
bool mark[MX];
vector<long long> stk, stmp;
string s;
long long n;
void del(long long ind) {
  long long r = inp[ind].r, l = inp[ind].l;
  if (r != -1) {
    inp[r].l = l;
  }
  if (l != -1) {
    inp[l].r = r;
  }
  if (l != -1 && r != -1 && mark[l]) {
    if (inp[l].c != inp[r].c) {
      if (mark[r]) {
        stmp.push_back(r);
        mark[r] = 0;
      }
      stmp.push_back(l);
      mark[l] = 0;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.size();
  for (long long i = 0; i < n; i++) {
    mark[i] = 1;
    inp[i].c = s[i] - 'a';
    if (i > 0) {
      if (inp[i].c != inp[i - 1].c) {
        if (mark[i - 1]) {
          stk.push_back(i - 1);
          mark[i - 1] = 0;
        }
        if (mark[i]) {
          stk.push_back(i);
          mark[i] = 0;
        }
      }
    }
    inp[i].l = i - 1;
    inp[i].r = i + 1;
    if (i + 1 == n) {
      inp[i].r = -1;
    }
  }
  long long cntr = 0;
  while (!stk.empty()) {
    cntr++;
    while (!stk.empty()) {
      long long x = stk.back();
      stk.pop_back();
      del(x);
    }
    while (!stmp.empty()) {
      stk.push_back(stmp.back());
      stmp.pop_back();
    }
  }
  cout << cntr << endl;
}
