#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char>> v;
string s;
int res, len;
void remove() {
  auto vend = remove_if(v.begin(), v.end(),
                        [](const pair<int, char>& p) { return p.first <= 0; });
  v.erase(vend, v.end());
}
void solve() {
  int mi = 10000001;
  for (int i = 0; i < long long((v).size()); ++i) {
    if (i == 0 || i == long long((v).size()) - 1)
      mi = min(mi, v[i].first);
    else
      mi = min(mi, (v[i].first + 1) / 2);
  }
  for (int i = 0; i < long long((v).size()); ++i) v[i].first -= mi;
  remove();
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].second == v[i - 1].second) {
      v[i].first += v[i - 1].first;
      v[i - 1].first = 0;
    }
  }
  remove();
  res += mi;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  len = 1;
  for (int i = 1; i < s.length(); ++i) {
    if (s[i] != s[i - 1]) {
      v.push_back({len, s[i - 1]});
      len = 1;
    } else
      ++len;
  }
  v.push_back({len, s[s.length() - 1]});
  while (long long((v).size()) > 1) solve();
  cout << res << endl;
  return 0;
}
