#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 1000000;
const int INF = 2147483647;
struct Group {
  int letter, nr;
} F[1 + N_MAX];
int f(int n) {
  if (n % 2 == 1) return n / 2 + 1;
  return n / 2;
}
int main() {
  string s;
  cin >> s;
  int l = s.length(), t = 1;
  F[1] = {s[0] - 'a', 1};
  for (int i = 1; i < l; i++) {
    if (s[i] == s[i - 1])
      F[t].nr++;
    else
      F[++t] = {s[i] - 'a', 1};
  }
  int ans = 0;
  while (t > 1) {
    int minimum = INF;
    for (int i = 2; i < t; i++) {
      minimum = min(minimum, f(F[i].nr));
    }
    minimum = min(min(minimum, F[1].nr), F[t].nr);
    ans += minimum;
    int r = 0;
    if (F[0].nr != minimum) F[0].nr -= minimum;
    for (int i = 2; i < t; i++)
      if (F[i].nr > 2 * minimum) {
        F[r] = {F[i].letter, F[i].nr - 2 * minimum};
        r++;
      }
    if (F[t].nr != minimum) F[r] = {F[t].letter, F[t].nr - minimum};
    t = r;
  }
  cout << ans;
  return 0;
}
