#include <bits/stdc++.h>
using namespace std;
struct SEG {
  int segment_length;
  char chars;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  SEG cur;
  vector<SEG> st;
  cur.segment_length = 0;
  cur.chars = '-';
  for (char x : s) {
    if (x == cur.chars) {
      cur.segment_length++;
    } else {
      if (cur.segment_length > 0) st.push_back(cur);
      cur.segment_length = 1;
      cur.chars = x;
    }
  }
  st.push_back(cur);
  int ans = 0;
  int p;
  while (((int)(st).size()) > 1) {
    vector<SEG> effect;
    for (int x = 0; x < ((int)(st).size()); x++) {
      cur = st[x];
      if (x == 0 or x == ((int)(st).size()) - 1) {
        cur.segment_length--;
      } else {
        cur.segment_length -= 2;
      }
      if (cur.segment_length <= 0) {
        continue;
      }
      if (effect.empty()) {
        effect.push_back(cur);
      } else {
        if (effect.back().chars == cur.chars) {
          effect.back().segment_length += cur.segment_length;
        } else {
          effect.push_back(cur);
        }
      }
    }
    st = effect;
    ans++;
  }
  cout << ans;
  return 0;
}
