#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const int N = 1e6 + 100;
const long long int mod = 1e9 + 7;
const long long int hashh = 311;
const long long int INF = 1e18;
struct saf {
  int nxt;
  int pre;
};
saf a[N];
bool mark[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i <= n; i++) a[i].nxt = i + 1, a[i].pre = i - 1;
  vector<long long int> v;
  if (s[0] != s[1]) v.push_back(1), mark[1] = true;
  if (s[n - 1] != s[n - 2]) v.push_back(n), mark[n] = true;
  for (int i = 1; i < n - 1; i++)
    if (s[i] != s[i - 1] || s[i] != s[i + 1])
      v.push_back(i + 1), mark[i + 1] = true;
  int cnt = 0;
  while (!v.empty()) {
    vector<long long int> vs;
    for (auto i : v) {
      a[a[i].nxt].pre = a[i].pre;
      a[a[i].pre].nxt = a[i].nxt;
      if (s[a[i].pre - 1] != s[a[i].nxt - 1] && a[i].pre > 0 && a[i].nxt <= n) {
        if (!mark[a[i].pre] && !mark[a[i].nxt])
          vs.push_back(a[i].pre), vs.push_back(a[i].nxt);
      }
    }
    for (auto i : vs) mark[i] = true;
    v = vs;
    cnt++;
  }
  cout << cnt;
}
