#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
char str[MAX];
int a[MAX], b[MAX];
int main(int argc, char const *argv[]) {
  while (scanf("%s", str) != EOF) {
    int len = strlen(str);
    int k = 1;
    a[k] = 1;
    b[k] = str[0] - 'a' + 1;
    for (int i = 1; i < len; i++) {
      if (str[i] == str[i - 1]) {
        a[k]++;
      } else {
        k++;
        a[k] = 1;
        b[k] = str[i] - 'a' + 1;
      }
    }
    if (k == 1) {
      printf("0\n");
      continue;
    }
    int ans = 0;
    int minn = MAX;
    int x = 1;
    bool mark = true;
    while (mark) {
      ans++;
      mark = false;
      bool lst = true;
      for (int i = x; i <= k; i++)
        if (a[i] > 0) {
          mark = true;
          if (i == x) {
            a[i]--;
            continue;
          }
          if (i == k) {
            a[k]--;
            continue;
          }
          if (a[i] == 1) {
            a[i] = 0;
            continue;
          }
          a[i] -= 2;
        }
      while (a[x] == 0 && x <= k) x++;
      if (x >= k) {
        break;
      }
      while (a[k] == 0 && k > 0) k--;
      int y = x;
      for (int i = x + 1; i <= k; i++) {
        if (a[i] != 0) {
          if (b[i] == b[y]) {
            a[y] += a[i];
            a[i] = 0;
          } else {
            y = i;
          }
        }
      }
      if (y == x) {
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
