#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  list<pair<int, int>> vl;
  int ans = 0;
  string s;
  cin >> s;
  for (size_t i = 0; i < s.length(); ++i) {
    if (s[i] != 'a') {
      s[i] = 'b';
    }
    if ((i == 0) || (vl.back().second != int(s[i] - 'a'))) {
      vl.push_back(make_pair(1, int(s[i] - 'a')));
    } else {
      ++vl.back().first;
    }
  }
  while (vl.size() > 1) {
    ++ans;
    auto cur = vl.begin();
    auto en = vl.end();
    --en;
    while (cur != vl.end()) {
      if (cur != vl.begin()) {
        --(cur->first);
      }
      if (cur != en) {
        --(cur->first);
      }
      cur->first = max(cur->first, 0);
      ++cur;
    }
    cur = vl.begin();
    auto nx = cur;
    while (cur != vl.end()) {
      nx = cur;
      ++nx;
      if (cur->first == 0) {
        vl.erase(cur);
      }
      cur = nx;
    }
    cur = vl.begin();
    nx = cur;
    if (nx != vl.end()) {
      ++nx;
    }
    while (nx != vl.end()) {
      if (cur->second == nx->second) {
        cur->first += nx->first;
        vl.erase(nx);
        nx = cur;
        ++nx;
        continue;
      }
      cur = nx;
      ++nx;
    }
  }
  cout << ans << endl;
}
