#include <bits/stdc++.h>
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
using namespace std;
const int maxn = 1e6 + 5;
char s[maxn];
struct node {
  char ch;
  int cnt;
} a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> (s + 1);
  int n = strlen(s + 1);
  int m = 0;
  char last = '#';
  for (long long i = 1; i <= n; ++i) {
    if (s[i] == last)
      a[m].cnt++;
    else {
      a[++m].cnt = 1;
      a[m].ch = last = s[i];
    }
  }
  int ans = 0;
  a[0].ch = '#';
  while (m > 1) {
    for (long long i = 1; i <= m; ++i)
      a[i].cnt -= (i == 1 || i == m ? 1 : min(2, a[i].cnt));
    int len = m;
    m = 0;
    for (long long i = 1; i <= len; ++i) {
      if (a[i].cnt == 0) continue;
      if (a[i].ch == a[m].ch)
        a[m].cnt += a[i].cnt;
      else
        a[++m] = a[i];
    }
    ++ans;
  }
  cout << ans << endl;
}
