#include <bits/stdc++.h>
using namespace std;
int main() {
  int count = 1, faster, N = 0, shag = 0;
  string s;
  char letter;
  vector<pair<int, char>> a;
  getline(cin, s);
  letter = s[0];
  for (int now = 1; now < s.size(); now++) {
    if (s[now] == letter) {
      count++;
    } else {
      pair<int, char> temp;
      temp.first = count;
      temp.second = letter;
      a.push_back(temp);
      letter = s[now];
      count = 1;
    }
  }
  pair<int, char> temp;
  temp.first = count;
  temp.second = letter;
  a.push_back(temp);
  while (a.size() > 1) {
    faster = min(a[0].first, a[a.size() - 1].first);
    for (int i = 1; i < a.size() - 2; i++) {
      if ((a[i].first + 1) / 2 < faster) faster = (a[i].first + 1) / 2;
    }
    a[0].first = a[0].first - faster;
    a[a.size() - 1].first = a[a.size() - 1].first - faster;
    int i = 1;
    while (i < a.size() - 1) {
      if (a[i].first <= faster * 2)
        a.erase(a.begin() + i);
      else
        i++;
    }
    shag += faster;
    if (a[0].first <= 0) a.erase(a.begin());
    if (a[a.size() - 1].first <= 0) a.erase(a.begin() + a.size() - 1);
    i = 1;
    if (a.size() > 0) {
      letter = a[0].second;
      while (i <= a.size() - 1) {
        if (a[i].second == letter) {
          a[i - 1].first = a[i - 1].first + a[i].first;
          a.erase(a.begin() + i);
        } else {
          letter = a[i].second;
          i++;
        }
      }
    }
  }
  cout << shag;
}
