#include <bits/stdc++.h>
using namespace std;
void setL(int, int);
void setR(int, int);
string s;
vector<int> flag;
vector<int> nn;
vector<int> d;
struct node {
  node() {}
  char val;
  int l, r;
  bool ok;
  bool check() {
    if (!ok) return false;
    bool ans = false;
    if (l != -1 && s[l] != val) {
      ans = true;
    }
    if (r != s.size() && s[r] != val) {
      ans = true;
    }
    if (ans) {
      if (l != -1) flag.push_back(l);
      if (r != s.size()) flag.push_back(r);
    }
    return ans;
  }
  void del() {
    ok = false;
    if (l != -1) setR(l, r);
    if (r != s.size()) setL(l, r);
  }
};
node v[1123456];
void setL(int l, int r) { v[r].l = l; }
void setR(int l, int r) { v[l].r = r; }
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    v[i].val = s[i];
    v[i].l = i - 1;
    v[i].r = i + 1;
    v[i].ok = true;
  }
  for (int i = 0; i < s.size(); ++i) {
    if (v[i].check()) d.push_back(i);
  }
  int ans = 0;
  while (!d.empty()) {
    ans++;
    for (int i = 0; i < d.size(); ++i) {
      v[d[i]].del();
    }
    d.clear();
    nn.clear();
    for (int i = 0; i < flag.size(); ++i) nn.push_back(flag[i]);
    flag.clear();
    for (int i = 0; i < nn.size(); ++i) {
      if (v[nn[i]].check()) {
        d.push_back(nn[i]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
