#include <bits/stdc++.h>
using namespace std;
deque<int> que, t1;
deque<char> s, t2;
int main() {
  int n = 0, cnt = 0;
  char c, last = 0;
  while (scanf("%c", &c) != EOF && c != '\n') {
    if (c >= 'a' && c <= 'z') {
      if (c == last) {
        que.back()++;
      } else {
        que.push_back(1);
        s.push_back(c);
      }
      last = c;
    }
  }
  while (!que.empty()) {
    int i = 0;
    while (!que.empty()) {
      int x = que.front();
      if (i != 0 && que.size() != 1) {
        x--;
      }
      if (x > 1) {
        t1.push_back(x - 1);
        t2.push_back(s.front());
      }
      que.pop_front();
      s.pop_front();
      i++;
    }
    while (!t1.empty()) {
      int x = t1.front();
      char y = t2.front();
      t1.pop_front();
      t2.pop_front();
      que.push_back(x);
      s.push_back(y);
      while (t2.front() == y) {
        que.back() += t1.front();
        t1.pop_front();
        t2.pop_front();
      }
    }
    cnt++;
    if (que.size() == 1) {
      break;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
