#include <bits/stdc++.h>
using namespace std;
typedef struct node {
  int l;
  char c;
  node* no;
} node;
int main() {
  string s;
  cin >> s;
  node* n = (node*)malloc(1 * sizeof(node));
  node* temp = (node*)malloc(1 * sizeof(node));
  temp = n;
  for (int i = 0; i < s.length(); i++) {
    char c1 = s[i];
    int l = i, r;
    while (i < s.length() && s[i] == c1) {
      i++;
    }
    i--;
    r = i;
    node* t1 = (node*)malloc(1 * sizeof(node));
    t1->l = r - l + 1;
    t1->c = c1;
    temp->no = t1;
    temp = t1;
  }
  temp->no = NULL;
  int st = 0;
  node* prev;
  while (n->no != NULL && n->no->no != NULL) {
    temp = n->no;
    bool f = 0, f1 = 0;
    prev = n;
    while (temp != NULL) {
      if (f == 0) {
        temp->l--;
        f1 = 0;
        if (temp->l < 1) {
          prev->no = temp->no;
          f1 = 1;
        }
        f = 1;
      } else if (temp->no == NULL) {
        temp->l--;
        f1 = 0;
        if (temp->l < 1) {
          prev->no = temp->no;
          f1 = 1;
        }
      } else {
        temp->l--;
        temp->l--;
        f1 = 0;
        if (temp->l < 1) {
          prev->no = temp->no;
          f1 = 1;
        }
      }
      temp = temp->no;
      if (f1 == 0) {
        prev = prev->no;
      }
    }
    temp = n->no;
    while (temp != NULL && temp->no != NULL) {
      while (temp->no != NULL && temp->c == temp->no->c) {
        temp->l = temp->l + temp->no->l;
        temp->no = temp->no->no;
      }
      temp = temp->no;
    }
    st++;
  }
  cout << st << "\n";
  return 0;
}
