#include <bits/stdc++.h>
using namespace std;
string s;
class node {
 public:
  char ch;
  int cou;
  node *prev = nullptr;
  node *next = nullptr;
  node(char ch1, int cou1) {
    ch = ch1;
    cou = cou1;
  }
};
int step(node *q) {
  int ans = 0;
  if (q->ch != '@' && (q->next || q->prev && q->prev->ch != '@')) {
    ans++;
    q->cou--;
  }
  if (q->next != nullptr) ans += step(q->next);
  if (q->cou == 0) {
    if (q->next) q->next->prev = q->prev;
    if (q->prev) q->prev->next = q->next;
  }
  return ans;
}
void norm(node *q) {
  while (q->next && q->next->ch == q->ch) {
    q->cou += q->next->cou;
    q->next = q->next->next;
    if (q->next) q->next->prev = q;
  }
  if (q->next) norm(q->next);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  s += '@';
  node *q = new node(s[0], 1);
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == q->ch)
      q->cou++;
    else {
      node *w = new node(s[i], 1);
      w->next = q;
      q->prev = w;
      q = w;
    }
  }
  int ans = 0;
  while (step(q)) {
    norm(q);
    ans++;
  }
  cout << ans;
  return 0;
}
