#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
char a[1000005];
int n, l[1000005], r[1000005], t, v[1000005];
vector<int> q, p;
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> s;
  n = s.length();
  for (int i = 0; i < n; i++) a[i + 1] = s[i];
  for (int i = 1; i <= n; i++) {
    if ((i > 1 && a[i] != a[i - 1]) || (i < n && a[i] != a[i + 1]))
      q.push_back(i), v[i] = 1;
    l[i] = i - 1;
    r[i] = i + 1;
    if (i == n) r[i] = -1;
    if (i == 1) l[i] = -1;
  }
  while (q.size()) {
    t++;
    for (int i : q) {
      int lt = l[i], rt = r[i];
      if (rt != -1) l[rt] = lt;
      if (lt != -1) r[lt] = rt;
      if (lt == -1 || rt == -1) continue;
      p.push_back(lt);
      p.push_back(rt);
    }
    q.clear();
    for (int j : p) {
      if (v[j]) continue;
      if (l[j] != -1 && a[l[j]] != a[j]) q.push_back(j), v[j] = 1;
      if (v[j]) continue;
      if (r[j] != -1 && a[r[j]] != a[j]) q.push_back(j), v[j] = 1;
    }
    p.clear();
  }
  cout << t;
}
