#include <bits/stdc++.h>
using namespace std;
const char *fin = "";
const char *fon = "";
const int OO = (int)(1e9 + 7);
const int MAXN = (int)(1e6 + 6);
char *s;
int n;
set<int> st;
vector<int> del_list;
int link[MAXN][2];
void Update(int x) {
  if (x == 0 || x == n + 1) return;
  if (st.count(x)) st.erase(x);
  if (link[x][0] != 0 && s[link[x][0]] != s[x]) st.emplace(x);
  if (link[x][1] != n + 1 && s[link[x][1]] != s[x]) st.emplace(x);
}
int Sol() {
  for (int res = 0;; ++res) {
    if (st.empty()) return res;
    del_list.clear();
    for (auto it : st) del_list.emplace_back(it);
    for (auto it : del_list) {
      int pre = link[it][0];
      int nxt = link[it][1];
      link[pre][1] = nxt;
      link[nxt][0] = pre;
      Update(pre);
      Update(nxt);
      st.erase(it);
    }
  }
}
void Inp() {
  s = (char *)calloc(MAXN, sizeof(char));
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    if (i != 1 && s[i] != s[i - 1]) st.insert(i);
    if (i != n && s[i] != s[i + 1]) st.insert(i);
    link[i][0] = i - 1;
    link[i][1] = i + 1;
  }
  printf("%d", Sol());
}
int main(int argc, char *argv[]) {
  Inp();
  return 0;
}
