#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
template <class T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
const int maxn = 1e6 + 10;
char s[maxn];
int r[maxn], n, bel[maxn], ri[maxn], cnt;
vector<int> d;
void del() {
  int p = 0;
  for (int i = 0; i < n + 1;) {
    while (d[p] < r[i]) p++;
    if (r[i] == d[p]) {
      if (r[i] == ri[bel[r[i]]]) ri[bel[r[i]]] = r[i] - 1;
      r[i] = r[r[i]];
    } else
      i = r[i];
  }
  d.clear();
}
void print() {
  for (int i = r[0]; i < n + 1; i = r[i]) printf("%c", s[i]);
  puts("");
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 0; i <= n; i++) {
    r[i] = i + 1;
  }
  cnt = 0;
  for (int i = 1, j; i <= n; i = j) {
    j = i;
    while (s[j] == s[i] && j <= n) bel[j++] = cnt;
    ri[cnt++] = j - 1;
  }
  int ans = 0;
  while (1) {
    char pre = 0;
    int bef = 0;
    for (int i = r[0]; i < n + 1; i = r[i]) {
      if (i != r[0] && s[i] != pre) d.push_back(i);
      bef = i;
      i = ri[bel[i]];
      pre = s[i];
      if (r[i] != n + 1 && s[i] != s[r[i]] && i != bef) d.push_back(i);
    }
    if (d.size() == 0) {
      printf("%d\n", ans);
      return 0;
    }
    ans++;
    del();
  }
  return 0;
}
