#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  string t;
  cin >> t;
  vector<char> s;
  vector<int> c;
  for (int i = 0; i < t.size();) {
    s.push_back(t[i]);
    int j = i;
    while (j < t.size() && t[j] == t[i]) j++;
    c.push_back(j - i);
    i = j;
  }
  int total = 0;
  while (s.size() > 1) {
    int m = INT_MAX, index;
    for (int i = 0; i < s.size(); ++i)
      if (m > c[i]) {
        m = c[i];
        index = i;
      }
    int turns =
        ((index == 0 || index == s.size() - 1) ? c[index]
                                               : c[index] / 2 + (c[index] % 2));
    total += turns;
    c[0] -= turns;
    c[c.size() - 1] -= turns;
    for (int i = 1; i < s.size() - 1; ++i) c[i] -= (2 * turns);
    vector<char> ns;
    vector<int> nc;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (c[i] > 0) {
        if (ns.size() > 0 && ns.back() == s[i])
          nc[nc.size() - 1] += c[i];
        else {
          ns.push_back(s[i]);
          nc.push_back(c[i]);
        }
      }
    }
    s = ns;
    c = nc;
  }
  cout << total << endl;
  return 0;
}
