#include <bits/stdc++.h>
using namespace std;
int n;
set<int> curr, S;
vector<int> c;
string s;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; ++i) {
    S.insert(i);
    if (i > 0 && s[i - 1] != s[i])
      curr.insert(i);
    else if (i + 1 < n && s[i + 1] != s[i])
      curr.insert(i);
  }
  int ans = 0;
  while (!curr.empty()) {
    ++ans;
    for (auto it : curr) {
      S.erase(it);
    }
    for (auto it : curr) {
      auto f = S.upper_bound(it);
      if (f != S.end()) c.push_back(*f);
      if (f != S.begin()) c.push_back(*prev(f));
    }
    curr.clear();
    sort((c).begin(), (c).end());
    c.erase(unique((c).begin(), (c).end()), c.end());
    for (auto it : c) {
      auto f = S.find(it);
      if (next(f) != S.end() && s[*next(f)] != s[*f])
        curr.insert(*f);
      else if (f != S.begin() && s[*prev(f)] != s[*f])
        curr.insert(*f);
    }
    c.clear();
  }
  cout << ans;
}
