#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
string s;
vector<pair<int, int> > vec;
vector<pair<int, int> > boz;
bool chk() {
  int n = vec.size();
  if (n <= 1) return (0);
  for (int i = 0; i < n; i++) {
    if (i == 0 or i == n - 1)
      vec[i].second--;
    else
      vec[i].second -= 2;
  }
  boz.clear();
  for (auto j : vec) {
    if (j.second > 0) {
      if (boz.empty()) {
        boz.push_back(j);
        ;
      } else if (boz.back().first == j.first) {
        boz.back().second += j.second;
      } else {
        boz.push_back(j);
        ;
      }
    }
  }
  swap(boz, vec);
  return (1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  for (auto i : s) {
    if (vec.empty()) {
      vec.push_back(pair<int, int>(i - 'a', 1));
      ;
    } else if (i - 'a' == vec.back().first) {
      vec.back().second++;
    } else {
      vec.push_back(pair<int, int>(i - 'a', 1));
      ;
    }
  }
  int cnt = 0;
  while (1) {
    if (chk()) {
      cnt++;
    } else {
      return (cout << cnt, 0);
      ;
    }
  }
  return (0);
}
