#include <bits/stdc++.h>
using namespace std;
const int infinity = 999999999;
int minimum_ops(const list<pair<char, int>>& groups);
int perform(list<pair<char, int>>& groups, int ops);
int merge(list<pair<char, int>>& groups);
int main() {
  string s;
  cin >> s;
  list<pair<char, int>> groups;
  char last = '0';
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == last)
      count++;
    else {
      if (count) groups.push_back(make_pair(last, count));
      last = s[i];
      count = 1;
    }
  }
  if (count) groups.push_back(make_pair(last, count));
  int ops = 0;
  while (groups.size() > 1) {
    int m = minimum_ops(groups);
    ops += m;
    perform(groups, m);
    merge(groups);
  }
  cout << ops << '\n';
}
int minimum_ops(const list<pair<char, int>>& groups) {
  int best = infinity;
  for (auto i = groups.begin(); i != groups.end(); i++) {
    auto next = i;
    next++;
    if (i == groups.begin() || next == groups.end())
      best = min(best, i->second);
    else
      best = min(best, (i->second + 1) / 2);
  }
  return best;
}
int perform(list<pair<char, int>>& groups, int ops) {
  for (auto i = groups.begin(); i != groups.end();) {
    auto next = i;
    next++;
    if (i == groups.begin() || next == groups.end())
      i->second -= ops;
    else
      i->second -= 2 * ops;
    if (i->second <= 0) groups.erase(i);
    i = next;
  }
}
int merge(list<pair<char, int>>& groups) {
  for (auto i = groups.begin(); i != groups.end();) {
    auto next = i;
    next++;
    if (next == groups.end()) break;
    if (i->first == next->first) {
      next->second += i->second;
      groups.erase(i);
    }
    i = next;
  }
}
