#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, cnt, cur, ans;
int si[N];
char co[N];
string s;
int main() {
  cin >> s;
  n = s.length();
  for (int i = n; i >= 1; i--) s[i] = s[i - 1];
  si[++cnt] = 1;
  co[cnt] = s[1];
  for (int i = 2; i <= n; i++) {
    if (s[i] == s[i - 1])
      si[cnt]++;
    else {
      si[++cnt] = 1;
      co[cnt] = s[i];
    }
  }
  while (cnt > 1) {
    cur = 0;
    for (int i = 1; i <= cnt; i++) {
      if (i == 1 || i == cnt)
        si[i]--;
      else
        si[i] -= 2;
    }
    for (int i = 1; i <= cnt; i++) {
      if (si[i] <= 0) continue;
      if (co[i] == co[cur])
        si[cur] += si[i];
      else {
        si[++cur] = si[i];
        co[cur] = co[i];
      }
    }
    ans++;
    cnt = cur;
  }
  cout << ans;
  return 0;
}
