#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
struct Node {
  char x;
  int id;
  Node* prev;
  Node* after;
};
vector<Node*> tmp, maybe;
string a;
int done[N];
int main() {
  cin >> a;
  Node *last = NULL, *fir = NULL;
  for (int i = 0; i < a.length(); i++) {
    Node* cur = new Node;
    cur->id = i;
    cur->x = a[i];
    cur->after = NULL;
    if (last == NULL) {
      last = cur;
      cur->after = NULL;
      fir = cur;
      cur->prev = NULL;
    } else {
      last->after = cur;
      cur->prev = last;
      last = cur;
    }
  }
  Node* use;
  for (use = fir; use != NULL; use = use->after) {
    if ((use->after != NULL) && ((use->after)->x != use->x)) {
      if (!done[use->id]) {
        done[use->id] = 1;
        tmp.push_back(use);
      }
      done[(use->after)->id] = 1;
      tmp.push_back(use->after);
    }
  }
  int sol = 0;
  while ((int)tmp.size() != 0) {
    sol++;
    for (int i = 0; i < tmp.size(); i++) {
      if (tmp[i]->prev != NULL) {
        (tmp[i]->prev)->after = tmp[i]->after;
        maybe.push_back(tmp[i]->prev);
      }
      if (tmp[i]->after != NULL) {
        (tmp[i]->after)->prev = tmp[i]->prev;
        maybe.push_back(tmp[i]->after);
      }
    }
    tmp.clear();
    for (int i = 0; i < maybe.size(); i++) {
      if (!done[maybe[i]->id]) {
        if (maybe[i]->prev != NULL) {
          if ((maybe[i]->prev)->x != maybe[i]->x) {
            tmp.push_back(maybe[i]);
            done[maybe[i]->id] = 1;
          }
        }
      }
      if (!done[maybe[i]->id]) {
        if (maybe[i]->after != NULL) {
          if ((maybe[i]->after)->x != maybe[i]->x) {
            tmp.push_back(maybe[i]);
            done[maybe[i]->id] = 1;
          }
        }
      }
    }
    maybe.clear();
  }
  printf("%d\n", sol);
  return 0;
}
