#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int parent[MAXN], size[MAXN];
int n;
vector<int> erased;
set<int> st;
int Find(int x) {
  if (x == parent[x]) return x;
  return parent[x] = Find(parent[x]);
}
void Union(int x, int y) {
  x = Find(x), y = Find(y);
  if (x != y) {
    parent[y] = x;
    size[x] += size[y];
  }
}
void init() {
  for (int i = 0; i < n; i++) {
    parent[i] = i;
    size[i] = 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  n = s.size();
  init();
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      Union(i - 1, i);
    }
  }
  for (int i = 0; i < n; i++) {
    st.insert(Find(i));
  }
  int ans = 0;
  while (st.size() >= 2) {
    ans++;
    erased.clear();
    for (auto it = st.begin(); it != st.end(); it++) {
      if (it == st.begin() || it == --st.end())
        size[*it] -= 1;
      else
        size[*it] -= 2;
      if (size[*it] <= 0) erased.push_back(*it);
    }
    for (int ee : erased) {
      st.erase(ee);
    }
    erased.clear();
    for (auto it = st.begin(); it != st.end(); it++) {
      if (it == st.begin()) continue;
      auto tt = it;
      tt--;
      if (s[Find(*it)] == s[Find(*tt)]) {
        Union(*it, *tt);
        erased.push_back(*tt);
      }
    }
    for (int ee : erased) {
      st.erase(ee);
    }
  }
  cout << ans;
  return 0;
}
