#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
char s[N];
int n;
int l[N], r[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n + 1; i++) l[i] = i - 1;
  for (int i = 0; i <= n; i++) r[i] = i + 1;
  set<int> dels, nxtdels;
  for (int i = 1; i <= n; i++) {
    bool del = 0;
    del |= (i - 1 >= 1 && s[i] != s[i - 1]);
    del |= (i + 1 <= n && s[i] != s[i + 1]);
    if (del) dels.insert(i);
  }
  int ans = 0;
  while (1) {
    if (dels.empty()) break;
    ans++;
    for (int x : dels) {
      r[l[x]] = r[x];
      l[r[x]] = l[x];
      if (l[x] >= 1 && l[x] <= n && r[x] >= 1 && r[x] <= n) {
        if (s[l[x]] != s[r[x]] && dels.find(l[x]) == dels.end())
          nxtdels.insert(l[x]);
        if (s[l[x]] == s[r[x]] && nxtdels.find(l[x]) != nxtdels.end())
          nxtdels.erase(l[x]);
        if (s[l[x]] != s[r[x]] && dels.find(r[x]) == dels.end())
          nxtdels.insert(r[x]);
        if (s[l[x]] == s[r[x]] && nxtdels.find(r[x]) != nxtdels.end())
          nxtdels.erase(r[x]);
      }
    }
    dels = nxtdels;
    nxtdels.clear();
  }
  printf("%d\n", ans);
}
