#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  s.push_back('~');
  list<pair<char, int>> l;
  int siz = 0;
  for (int i = 0; i < (int)s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) {
      ++siz;
      l.insert(l.end(), make_pair(s[i], siz));
      siz = 0;
    } else
      ++siz;
  }
  int ans = 0;
  while (l.size() > 1) {
    for (auto it = l.begin(); it != l.end();) {
      auto ed = l.end();
      ed--;
      if (it != l.begin() && it != ed) {
        it->second -= 2;
        if (it->second <= 0)
          it = l.erase(it);
        else
          it++;
      } else {
        it->second -= 1;
        if (it->second <= 0)
          it = l.erase(it);
        else
          it++;
      }
    }
    for (auto it = l.begin(); it != l.end();) {
      auto tmp = it;
      tmp++;
      while (tmp != l.end() && it->first == tmp->first) {
        it->second += tmp->second;
        tmp = l.erase(tmp);
      }
      it = tmp;
    }
    ++ans;
  }
  cout << ans << '\n';
  return 0;
}
