#include <bits/stdc++.h>
using namespace std;
int N, Size = 0, Ans = 0, c[1000005], l[1000005], Max = 0;
char str[1000005];
int main() {
  cin >> str + 1;
  N = strlen(str + 1);
  for (int i = 1; i <= N; i++) {
    if (c[Size] != str[i])
      c[++Size] = str[i], l[Size] = 1;
    else
      l[Size]++;
  }
  while (Size > 1) {
    int Min = min(l[1], l[Size]), K = 0;
    for (int i = 2; i < Size; i++) Min = min(Min, (l[i] + 1) / 2);
    l[1] -= Min, l[Size] -= Min;
    for (int i = 2; i < Size; i++) l[i] -= 2 * Min;
    for (int i = 1; i <= Size; i++)
      if (l[i] > 0) l[++K] = l[i], c[K] = c[i];
    Size = K;
    K = 0;
    for (int i = 1; i <= Size; i++) {
      if (c[i] != c[K])
        c[++K] = c[i], l[K] = l[i];
      else
        l[K] += l[i];
    }
    Size = K;
    Ans += Min;
  }
  cout << Ans;
  return 0;
}
