#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 6;
int n, ans;
string s;
vector<pair<long long, long long> > gp1, gp2;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> s;
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      gp1.push_back({s[i - 1] - 'a', cnt});
      cnt = 0;
    }
    cnt++;
  }
  gp1.push_back({s[s.size() - 1] - 'a', cnt});
  while (1 < gp1.size()) {
    ans++;
    gp2.clear();
    if (1 < gp1[0].second) gp2.push_back({gp1[0].first, gp1[0].second - 1});
    for (int i = 1; i + 1 < gp1.size(); i++)
      if (2 < gp1[i].second) {
        if (gp2.size() && gp2.back().first == gp1[i].first) {
          gp1[i].second += gp2.back().second;
          gp2.pop_back();
        }
        gp2.push_back({gp1[i].first, gp1[i].second - 2});
      }
    if (1 < gp1.back().second) {
      if (gp2.size() && gp2.back().first == gp1.back().first) {
        gp1.back().second += gp2.back().second;
        gp2.pop_back();
      }
      gp2.push_back({gp1.back().first, gp1.back().second - 1});
    }
    gp1 = gp2;
  }
  cout << ans << "\n";
  return 0;
}
