#include <bits/stdc++.h>
using namespace std;
char s[2000000];
struct ooxx {
  int x, num;
} a[2000000];
int tot, first = 1, last, ans;
bool fck = true;
int main() {
  scanf("%s", s + 1);
  int lth = strlen(s + 1);
  a[++tot].x = s[1] - 'a' + 1, a[tot].num = 1;
  for (int i = 2; i <= lth; ++i) {
    if (s[i] != s[i - 1])
      a[++tot].x = s[i] - 'a' + 1, a[tot].num = 1;
    else
      a[tot].num++;
  }
  last = tot;
  while (1) {
    if (first == last) break;
    ans++;
    while (1) {
      if (a[first].num <= 1)
        first++;
      else
        break;
      if (first >= last) {
        fck = false;
        break;
      }
    }
    if (!fck) break;
    while (1) {
      if (a[last].num <= 1)
        last--;
      else
        break;
      if (first >= last) {
        fck = false;
        break;
      }
    }
    if (!fck) break;
    a[first].num--, a[last].num--;
    int tott = first;
    for (int i = first + 1; i <= last - 1; ++i) {
      if (a[i].x == a[tott].x) {
        a[tott].num += a[i].num;
        continue;
      }
      a[++tott].x = a[i].x, a[tott].num = a[i].num - 2;
      if (a[tott].num <= 0) tott--;
    }
    if (tott < last) {
      if (a[tott].x == a[last].x)
        a[tott].num += a[last].num, last = tott;
      else
        a[++tott].x = a[last].x, a[tott].num = a[last].num, last = tott;
    }
  }
  printf("%d", ans);
  return 0;
}
