#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
const long long INF = 100000000000000LL;
const long long mod = 998244353;
char s[maxn];
typedef struct Node {
  char c;
  int num;
} node;
node t[maxn];
int vis[maxn];
void solve() {
  memset(vis, 0, sizeof(vis));
  memset(t, 0, sizeof(t));
  int len = strlen(s + 1);
  int cnt = 1;
  t[1].num = 1;
  t[1].c = s[1];
  for (int i = 2; i <= len; i++) {
    if (s[i] != s[i - 1]) {
      ++cnt;
      t[cnt].c = s[i];
    }
    t[cnt].num++;
  }
  int ans = 0;
  if (cnt != 1) {
    while (cnt > 1) {
      int minoper = min(t[cnt].num, t[1].num);
      for (int i = 2; i < cnt; i++) minoper = min(minoper, (t[i].num + 1) / 2);
      int pos = 0;
      for (int i = 1; i <= cnt; i++) {
        if (i == 1 || i == cnt) {
          t[i].num -= minoper;
        } else {
          t[i].num -= minoper * 2;
        }
        if (t[i].num <= 0) continue;
        if (t[i].c == t[pos].c)
          t[pos].num += t[i].num;
        else
          t[++pos] = t[i];
      }
      ans += minoper;
      cnt = pos;
    }
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  while (~scanf("%s", s + 1)) {
    solve();
  }
  return 0;
}
