#include <bits/stdc++.h>
using namespace std;
int rez = 0;
vector<pair<char, int> > v;
vector<pair<char, int> > newv;
string s;
void form() {
  int n = s.size();
  v.push_back({s[0], 1});
  for (int i = 1; i < n; i++) {
    if (s[i] == (*(v.end() - 1)).first)
      (*(v.end() - 1)).second++;
    else
      v.push_back({s[i], 1});
  }
}
void unite() {
  newv.clear();
  int n = v.size();
  int i = 0;
  while (v[i].second <= 0 && i < n) i++;
  newv.push_back(v[i]);
  for (i = i + 1; i < n; i++) {
    if (v[i].second > 0) {
      if ((*(newv.end() - 1)).first == v[i].first) {
        (*(newv.end() - 1)).second += v[i].second;
      } else
        newv.push_back(v[i]);
    }
  }
  v = newv;
}
void findanddel() {
  int n = v.size();
  int t = min(v[0].second, v[n - 1].second);
  for (int i = 1; i < n - 1; i++) t = min(t, (v[i].second + 1) / 2);
  rez += t;
  v[0].second -= t;
  v[n - 1].second -= t;
  for (int i = 1; i < n - 1; i++) {
    v[i].second -= 2 * t;
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> s;
  int n = s.size();
  v.push_back({s[0], 1});
  for (int i = 1; i < n; i++) {
    if (s[i] == (*(v.end() - 1)).first)
      (*(v.end() - 1)).second++;
    else
      v.push_back({s[i], 1});
  }
  while (v.size() > 1) {
    findanddel();
    unite();
  }
  cout << rez;
}
