#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 13;
const double esp = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const long long INF = 0x3f3f3f3f3f3f3f;
const long long M = 2e6;
char a[maxn];
std::vector<pair<int, char> > vv;
std::vector<pair<int, char> > temp;
int main() {
  scanf("%s", a + 1);
  int n = strlen(a + 1);
  int s = 1;
  char t = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] == t)
      s++;
    else {
      vv.push_back(make_pair(s, t));
      t = a[i];
      s = 1;
    }
  }
  vv.push_back(make_pair(s, t));
  int ans = 0;
  int num = vv.size();
  while (num > 1) {
    ans++;
    vv[0].first -= 1;
    vv[num - 1].first -= 1;
    for (int i = 1; i < num - 1; i++) {
      vv[i].first -= 1;
    }
    temp.clear();
    int s = -1;
    char t = 0;
    for (int i = 0; i < num; i++) {
      if (vv[i].first <= 0) continue;
      if (s == -1) {
        s = vv[i].first;
        t = vv[i].second;
        continue;
      }
      if (vv[i].second != t) {
        temp.push_back(make_pair(t, s));
      } else {
        s += vv[i].first;
      }
    }
    if (s != -1) temp.push_back(make_pair(t, s));
    vv = temp;
    num = vv.size();
  }
  printf("%d\n", ans);
}
