#include <bits/stdc++.h>
using namespace std;
void timestamp(char const* const s, bool absolute = false);
vector<pair<char, int>> v;
void read() {
  string s;
  cin >> s;
  v.reserve(s.size());
  char c = s[0];
  int sz = 1;
  for (size_t i = 1; i < s.size(); ++i) {
    if (s[i] == c) {
      ++sz;
    } else {
      v.push_back({c, sz});
      c = s[i];
      sz = 1;
    }
  }
  v.push_back({c, sz});
}
void solve() {
  int ans = 0;
  while (v.size() >= 2) {
    int m = v[0].second;
    for (size_t i = 1; i < v.size() - 1; ++i) {
      m = min(m, (v[i].second + 1) / 2);
    }
    m = min(m, v.back().second);
    size_t off = 0;
    for (size_t i = 0; i < v.size(); ++i) {
      bool skipped = false;
      if (i == 0 || i == v.size() - 1) {
        if (v[i].second <= m) {
          ++off;
          skipped = true;
        } else {
          v[i].second -= m;
        }
      } else {
        if (v[i].second <= 2 * m) {
          ++off;
          skipped = true;
        } else {
          v[i].second -= 2 * m;
        }
      }
      if (!skipped) {
        if (i - off > 0 && v[i].first == v[i - off - 1].first) {
          v[i - off - 1].second += v[i].second;
          ++off;
        } else {
          v[i - off] = v[i];
        }
      }
    }
    v.resize(v.size() - off);
    ans += m;
  }
  cout << ans << endl;
}
void timestamp(char const* const s, bool absolute) {
  static double last = 0;
  double now = (static_cast<double>(clock()) / CLOCKS_PER_SEC) * 1000;
  if (absolute) {
    ;
  } else {
    ;
    last = now;
  }
}
int main() {
  timestamp("start");
  read();
  timestamp("read()");
  solve();
  timestamp("solve()");
  timestamp("total", true);
  return 0;
}
