#include <bits/stdc++.h>
using namespace std;
int main() {
  list<pair<char, int> > data;
  string str;
  cin >> str;
  int count = 0;
  char prev = 0;
  for (auto &c : str) {
    if (count == 0) {
      prev = c;
      count = 1;
    } else if (prev == c) {
      ++count;
    } else {
      data.push_back({prev, count});
      prev = c;
      count = 1;
    }
  }
  data.push_back({prev, count});
  int result = 0;
  int end = data.size() - 1;
  while (end > 0) {
    count = 0;
    for (auto it = data.begin(); it != data.end(); ++count) {
      if (it->second == 1) {
        it = data.erase(it);
        continue;
      } else {
        if (count == 0 || count == end) {
          --it->second;
        } else {
          if (it->second == 2) {
            it = data.erase(it);
            continue;
          } else {
            it->second -= 2;
          }
        }
      }
      ++it;
    }
    if (data.size() > 1) {
      for (auto it = ++data.begin(); it != data.end();) {
        auto it2 = std::prev(it);
        if (it->first == it2->first) {
          it2->second += it->second;
          it = data.erase(it);
        } else {
          ++it;
        }
      }
    }
    result++;
    end = data.size() - 1;
  }
  cout << result << endl;
  return 0;
}
