#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
pair<char, int> v[maxn], aux[maxn];
int n, k;
char s[maxn];
int main() {
  ios::sync_with_stdio(false);
  char ch;
  cin >> (s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    ch = s[i];
    if (v[k].first == ch)
      v[k].second++;
    else
      v[++k] = {ch, 1};
  }
  int answer = 0;
  while (k > 1) {
    answer++;
    for (int i = 1; i <= k; i++) {
      if (i == 1 || i == k)
        v[i].second = max(0, v[i].second - 1);
      else
        v[i].second = max(0, v[i].second - 2);
    }
    int newk = 0;
    for (int i = 1; i <= k; i++) {
      if (v[i].second == 0) continue;
      if (v[i].first == aux[newk].first)
        aux[newk].second += v[i].second;
      else
        aux[++newk] = v[i];
    }
    for (int i = 1; i <= newk; i++) v[i] = aux[i];
    k = newk;
  }
  cout << answer;
  return 0;
}
