#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  vector<int> num;
  vector<int> cc;
  for (int i = 0; i < str.length();) {
    char c = str[i];
    int tmp = 0;
    while (i < str.length() && str[i] == c) {
      tmp++;
      i++;
    }
    num.push_back(tmp);
    cc.push_back(c);
  }
  long long res = 0;
  while (1) {
    int minn = 1e9 + 7;
    if (num.size() == 1) break;
    for (int i = 0; i < num.size(); i++) {
      if (i == 0 || i == (int)num.size() - 1) {
        minn = min(minn, num[i]);
      } else
        minn = min(minn, (num[i] + 1) / 2);
    }
    res += minn;
    vector<int> tmp_num;
    vector<int> tmp_cc;
    for (int i = 0; i < num.size(); i++) {
      int x = num[i];
      if (i == 0 || i == (int)num.size() - 1) {
        x -= minn;
      } else
        x -= minn * 2;
      if (x > 0) {
        char ch;
        int len = tmp_cc.size();
        if (len > 0) {
          ch = tmp_cc[len - 1];
          if (ch == cc[i]) {
            tmp_num[len - 1] += x;
            continue;
          }
        }
        tmp_num.push_back(x);
        tmp_cc.push_back(cc[i]);
      }
    }
    num = tmp_num;
    cc = tmp_cc;
    if (num.size() <= 1) break;
  }
  cout << res << endl;
}
