#include <bits/stdc++.h>
using namespace std;
void FREOPEN() {
  freopen(
      ""
      ".in",
      "r", stdin);
  freopen(
      ""
      ".out",
      "w", stdout);
}
inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = 1000500, inf = 1e9 * 2, MOD = (int)1e9 + 7;
char CH[N];
const long long INF = 1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
int main() {
  scanf("%s", CH);
  string s = CH;
  int n = (int((s).size()));
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    if (i < n - 1 && s[i] != s[i + 1]) {
      if (!v.empty() && i - v.back().second <= 1)
        v.back().second = i + 1;
      else
        v.push_back({i, i + 1});
    }
  }
  int ans = (!v.empty());
  while (true) {
    bool del = 0;
    for (int i = 0; i < (int((v).size())); i++) {
      if (v[i].first - 1 >= 0 && v[i].second + 1 < n) {
        if (s[v[i].first - 1] != s[v[i].second + 1])
          del = 1, v[i].first--, v[i].second++;
      }
    }
    if (!del) break;
    ans++;
    vector<pair<int, int> > nex;
    for (auto i : v) {
      if (nex.empty() || nex.back().second < i.first - 1)
        nex.push_back(i);
      else
        nex.back().second = i.second;
    }
    v = nex;
  }
  cout << ans;
  return 0;
}
