#include <bits/stdc++.h>
using namespace std;
string s;
vector<pair<char, int> > mas, mas1;
int ans;
int main() {
  cin >> s;
  mas.push_back({'0', 0});
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != mas.back().first) {
      mas.push_back({s[i], 1});
    } else {
      mas[mas.size() - 1].second++;
    }
  }
  reverse(mas.begin(), mas.end());
  mas.pop_back();
  reverse(mas.begin(), mas.end());
  for (; mas.size() > 1;) {
    ans++;
    mas1.clear();
    mas1.push_back({'0', 0});
    for (int i = 0; i < mas.size(); i++) {
      mas[i].second -= 2;
    }
    mas[0].second++;
    mas[mas.size() - 1].second++;
    for (int i = 0; i < mas.size(); i++) {
      if (mas[i].second <= 0) continue;
      if (mas[i].first == mas1[mas1.size() - 1].first) {
        mas1[mas1.size() - 1].second += mas[i].second;
      } else {
        mas1.push_back(mas[i]);
      }
    }
    reverse(mas1.begin(), mas1.end());
    mas1.pop_back();
    reverse(mas1.begin(), mas1.end());
    mas = mas1;
  }
  cout << ans;
}
