#include <bits/stdc++.h>
using namespace std;
string s;
vector<pair<int, int>> pts[2];
inline void group_add(vector<pair<int, int>> &v, int val, int amt) {
  if (amt <= 0) return;
  if (!v.empty() and v.back().first == val)
    v.back().second += amt;
  else
    v.emplace_back(val, amt);
}
int main() {
  cin >> s;
  for (char c : s) group_add(pts[0], c - 'a', 1);
  int ans = 0, cnt = 0;
  while (pts[cnt & 1].size() >= 2) {
    auto &cur = pts[cnt & 1];
    auto &nxt = pts[++cnt & 1];
    int reps = min(cur[0].second, cur.back().second);
    for (unsigned i = 1; i < cur.size() - 1; i++) {
      reps = min(reps, (cur[i].second + 1) / 2);
    }
    nxt.clear();
    group_add(nxt, cur[0].first, cur[0].second - reps);
    for (unsigned i = 1; i < cur.size() - 1; i++) {
      group_add(nxt, cur[i].first, cur[i].second - 2 * reps);
    }
    group_add(nxt, cur.back().first, cur.back().second - reps);
    ans += reps;
  }
  printf("%d\n", ans);
}
