#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<pair<char, int>> v;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i == s.size() - 1 || s[i] != s[i + 1]) {
      cnt++;
      v.emplace_back(s[i], cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  int ans = 0;
  while (v.size() > 1) {
    ans++;
    for (int i = 0; i < v.size(); i++) v[i].second -= 2;
    v.front().second++, v.back().second++;
    vector<pair<char, int>> tmp;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second > 0) {
        tmp.push_back(v[i]);
      }
    }
    v = tmp;
    tmp.clear();
    for (int i = 0; i < v.size(); i++) {
      tmp.push_back(v[i]);
      int j = i + 1;
      while (tmp.back().first == v[j].first) {
        tmp.back().second += v[j].second;
        j++;
      }
      i = j - 1;
    }
    v = tmp;
  }
  printf("%d\n", ans);
  return 0;
}
