#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> n;
  vector<char> c;
  int i = 0;
  while (i < s.size()) {
    c.push_back(s[i]);
    int cnt = 1;
    ++i;
    while ((i < s.size()) && (s[i] == s[i - 1])) ++cnt, ++i;
    n.push_back(cnt);
  }
  int ans = 0;
  while (c.size() > 1) {
    int a = 1e9;
    int k = c.size();
    for (int i = 0; i < k; ++i) {
      if ((i == 0) || (i == k - 1))
        a = min(a, n[i]);
      else
        a = min(a, n[i] / 2 + n[i] % 2);
    }
    ans += a;
    vector<int> n1;
    vector<char> c1;
    for (int i = 0; i < k; ++i) {
      if ((i == 0) || (i == k - 1))
        n[i] -= a;
      else
        n[i] -= 2 * a;
      if (n[i] > 0) {
        if ((!c1.empty()) && (c1.back() == c[i]))
          n1.back() += n[i];
        else
          c1.push_back(c[i]), n1.push_back(n[i]);
      }
    }
    c = c1, n = n1;
  }
  cout << ans;
  return 0;
}
