#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int M = 1e9 + 7;
string s;
int i, len, n, mn, T, ans;
vector<int> sz;
int main() {
  cin >> s;
  n = s.size();
  for (i = len = 1; i <= n; i++, len++)
    if (i == n || (s[i] != s[i - 1])) {
      if (i == n || i == len || len > 2) s[T++] = s[i - 1], sz.push_back(len);
      len = 0;
    }
  for (mn = 1; (n = T) > 1;) {
    for (T = i = 0; i < n; i++) {
      if ((sz[T] = sz[i] - (!i || i + 1 == n ? mn : mn * 2)) > 0)
        if (T && s[i] == s[T - 1])
          sz[T - 1] += sz[T];
        else
          s[T++] = s[i];
    }
    ans += mn;
    mn = min(sz[0], sz[T - 1]);
    for (i = 1; i < T - 1; i++) mn = min(mn, max(sz[i] / 2, 1));
  }
  cout << ans << endl;
}
