#include <bits/stdc++.h>
using namespace std;
list<pair<long long, long long> > lt;
string s;
map<long long, char> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  long long l = (long long)s.length(), i = 0, ans = 0;
  while (i < l) {
    long long j = i;
    while (j < l && s[j] == s[i]) j++;
    lt.push_back({i, j - i});
    i = j;
  }
  while (1) {
    if ((long long)lt.size() <= 1) break;
    if ((long long)lt.size() == 2) {
      ans += min(lt.front().second, lt.back().second);
      break;
    }
    lt.front().second--;
    for (auto it = next(lt.begin()); it != prev(lt.end());) {
      it->second = max((long long)0, it->second - 2);
      if (it->second == 0)
        it = lt.erase(it);
      else
        it++;
    }
    lt.back().second--;
    if (lt.back().second == 0) lt.erase(prev(lt.end()));
    if (lt.front().second == 0) lt.erase(lt.begin());
    for (auto it = next(lt.begin()); it != lt.end();) {
      if (s[prev(it)->first] == s[it->first]) {
        prev(it)->second += it->second;
        it = lt.erase(it);
      } else
        it++;
    }
    ans++;
  }
  cout << ans << "\n";
}
