#include <bits/stdc++.h>
using namespace std;
vector<pair<char, int> > a;
const int oo = 1e9;
int cal(int i) {
  if (i == 0 || i == a.size() - 1)
    return a[i].second;
  else
    return a[i].second / 2 + a[i].second % 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  a.push_back(make_pair(s[0], 1));
  for (int i = 1; i < s.length(); i++)
    if (s[i] == a.back().first)
      a.back().second++;
    else
      a.push_back(make_pair(s[i], 1));
  int res = 0;
  while (a.size() > 1) {
    int mincost = oo;
    for (int i = 0; i < a.size(); i++) mincost = min(mincost, cal(i));
    res += mincost;
    vector<pair<char, int> > b;
    for (int i = 0; i < a.size(); i++)
      if (cal(i) > mincost) {
        int c = a[i].second;
        if (i == 0 || i == a.size() - 1)
          c -= mincost;
        else
          c -= mincost * 2;
        if (!b.size() || a[i].first != b.back().first)
          b.push_back(make_pair(a[i].first, c));
        else
          b.back().second += c;
      }
    a = b;
  }
  cout << res;
}
