#include <bits/stdc++.h>
using namespace std;
struct mystruct {
  char ch;
  int len;
  mystruct(char c, int l) {
    ch = c;
    len = l;
  }
};
int main() {
  int a, b, c, m, n;
  string str, no = "NO", yes = "YES";
  cin >> str;
  n = str.size();
  int last_step = 0;
  vector<mystruct> arr;
  int beg = 0;
  char last_ch = str[0];
  for (int i = 1; i < str.size(); ++i) {
    if (str[i] != last_ch) {
      arr.push_back(mystruct(last_ch, i - beg));
      last_ch = str[i];
      beg = i;
    }
  }
  if (str.size() - beg > 0) {
    arr.push_back(mystruct(last_ch, str.size() - beg));
  }
  for (int i = 0; i < 1000010; ++i) {
    vector<mystruct> new_arr;
    if (arr.size() <= 1) {
      break;
    }
    arr[0].len--;
    if (arr[0].len > 0) {
      new_arr.push_back(arr[0]);
    }
    for (int j = 1; j < arr.size() - 1; ++j) {
      arr[j].len -= 2;
      if (arr[j].len > 0) {
        if (new_arr.size() > 0 && new_arr[new_arr.size() - 1].ch == arr[j].ch) {
          new_arr[new_arr.size() - 1].len += arr[j].len;
        } else {
          new_arr.push_back(arr[j]);
        }
      }
    }
    arr[arr.size() - 1].len--;
    if (arr[arr.size() - 1].len > 0) {
      if (new_arr.size() > 0 &&
          new_arr[new_arr.size() - 1].ch == arr[arr.size() - 1].ch) {
        new_arr[new_arr.size() - 1].len += arr[arr.size() - 1].len;
      } else {
        new_arr.push_back(arr[arr.size() - 1]);
      }
    }
    ++last_step;
    arr = new_arr;
  }
  cout << last_step << endl;
  return 0;
}
