#include <bits/stdc++.h>
using namespace std;
const int N = 5009;
const int mod = 1e9 + 7;
int dp[N][N];
int sum[N][N];
string s;
void remove_one(pair<char, int> &it) {
  it = make_pair(it.first, it.second - 1);
}
void add2vector(pair<char, int> &it, vector<pair<char, int> > &a) {
  if (a.size() == 0 || a.back().first != it.first) {
    a.push_back(it);
    return;
  }
  a[a.size() - 1] = make_pair(it.first, a.back().second + it.second);
}
int main() {
  cin >> s;
  int i = 0;
  vector<pair<char, int> > a, b;
  while (s[i]) {
    int cnt = 1;
    while (s[i + 1] && s[i + 1] == s[i]) i++, cnt++;
    a.emplace_back(s[i - cnt + 1], cnt);
    i++;
  }
  int ans = 0;
  while (a.size() > 1) {
    bool del_flag = 0;
    b.clear();
    for (int i = 0; i + 1 < a.size(); i++)
      if (a[i].first != a[i + 1].first) {
        a[i].second--;
        a[i + 1].second--;
      }
    b.clear();
    for (int i = 0; i < a.size(); i++)
      if (a[i].second > 0) {
        add2vector(a[i], b);
      }
    a = b;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
