#include <bits/stdc++.h>
using namespace std;
int N, T, Z, i, DH[1000005], A[1000005][3], L, R, X, Y;
char C[1000005];
pair<int, int> F;
priority_queue<pair<int, int> > PQ;
void udt(int X) { PQ.push(pair<int, int>(-A[X][0], X)); }
void gabung() {
  if (X == L && Y == R) {
    R = L;
    return;
  }
  if (X == L) {
    L = A[Y][2];
    A[L][0] += A[L][0] - 2 * T;
    udt(L);
    return;
  }
  if (Y == R) {
    R = A[X][1];
    A[R][0] += A[R][0] - 2 * T;
    udt(R);
    return;
  }
  X = A[X][1];
  Y = A[Y][2];
  if (C[X] != C[Y]) {
    A[X][2] = Y;
    A[Y][1] = X;
    return;
  }
  if (X == L && Y == R) {
    L = R;
    return;
  }
  if (Y == R) {
    A[X][0] += A[X][0] + A[Y][0] - 4 * T;
    R = X;
  } else {
    A[X][2] = A[Y][2];
    A[A[Y][2]][1] = X;
    A[X][0] += A[Y][0] - 2 * T;
    if (X == L) {
      A[X][0] += A[Y][0] - 2 * T;
    }
  }
  A[Y][0] = 0;
  udt(X);
}
void wait() {
  string S;
  getline(cin, S);
}
void print() {
  int j;
  for (i = L; i != R; i = A[i][2]) {
    cout << C[i] << ' ' << i << ' ' << A[i][0] - 2 * T << ' ';
  }
  cout << C[R] << ' ' << R << ' ' << A[R][0] - 2 * T;
  cout << '\n';
  wait();
}
int main() {
  cin >> C;
  N = strlen(C);
  A[0][0] = 1;
  for (i = 1; i < N; i++) {
    if (C[i] == C[R]) {
      A[R][0]++;
    } else {
      R++;
      C[R] = C[i];
      A[R][0] = 1;
    }
  }
  A[0][2] = 1;
  A[0][0] *= 2;
  PQ.push(pair<int, int>(-A[0][0], 0));
  for (i = 1; i < R; i++) {
    A[i][1] = i - 1;
    A[i][2] = i + 1;
    PQ.push(pair<int, int>(-A[i][0], i));
  }
  if (R) {
    A[R][1] = R - 1;
    A[R][0] *= 2;
    PQ.push(pair<int, int>(-A[R][0], R));
  }
  for (T = 1; L < R; T++) {
    Z = 0;
    while (!PQ.empty() && (PQ.top().first >= -2 * T)) {
      F = PQ.top();
      PQ.pop();
      if (A[F.second][0] == -F.first) {
        DH[Z] = F.second;
        Z++;
      }
    }
    if (Z) {
      sort(DH, DH + Z);
      X = Y = DH[0];
      for (i = 1; i < Z; i++) {
        if (A[Y][2] == DH[i]) {
          Y = DH[i];
        } else {
          gabung();
          X = Y = DH[i];
        }
      }
      gabung();
    }
  }
  cout << T - 1 << '\n';
}
