#include <bits/stdc++.h>
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
vector<pair<int, int> > v, v2;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  string s;
  int kol, ans = 0;
  cin >> s;
  kol = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      if (s[i - 1] == 'a') v.push_back({kol, 1});
      if (s[i - 1] == 'b') v.push_back({kol, 2});
      if (s[i - 1] == 'c') v.push_back({kol, 3});
      kol = 1;
    } else
      kol++;
  }
  if (s[s.size() - 1] == 'a') v.push_back({kol, 1});
  if (s[s.size() - 1] == 'b') v.push_back({kol, 2});
  if (s[s.size() - 1] == 'c') v.push_back({kol, 3});
  while (1) {
    if (v.size() <= 1) break;
    ans++;
    v2.clear();
    for (int i = 0; i < v.size(); i++) {
      v[i].first--;
      if (v[i].first == 0) continue;
      if (v2.size() == 0)
        v2.push_back(v[i]);
      else {
        if (v[i].second == v2[v2.size() - 1].second)
          v2[v2.size() - 1].first += v[i].first;
        else
          v2.push_back(v[i]);
      }
    }
    v = v2;
  }
  cout << ans << endl;
  return 0;
}
