#include <bits/stdc++.h>
using namespace std;
void Debug() { cout << '\n'; }
template <class FIRST, class... REST>
void Debug(FIRST arg, REST... rest) {
  cout << arg << " ";
  Debug(rest...);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  if (!v.empty()) {
    for (int i = int(0); i < int((int)(v).size() - 1); i++) out << v[i] << ", ";
    out << v.back();
  }
  out << "]";
  return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& v) {
  out << "(" << v.first << ", " << v.second << ")";
  return out;
}
const int MAX_N = 1000010;
const int MAX_V = 100010;
const double eps = 1e-6;
const long long mod = 1000000007;
const int inf = 1 << 29;
const long long linf = 1LL << 60;
const double PI = 3.14159265358979323846;
int N;
vector<pair<int, int> > vec[MAX_N];
void solve() {
  string str;
  cin >> str;
  N = (int)(str).size();
  int prev = str[0] - 'a', cnt = 1;
  for (int i = int(1); i < int(N); i++) {
    int v = str[i] - 'a';
    if (prev != v) {
      vec[0].push_back(pair<int, int>(cnt, prev));
      cnt = 1;
      prev = v;
    } else
      cnt++;
  }
  vec[0].push_back(pair<int, int>(cnt, prev));
  for (int ans = 0;; ans++) {
    if ((int)(vec[ans]).size() <= 1) {
      cout << ans << "\n";
      return;
    }
    int n = (int)(vec[ans]).size();
    vec[ans][n - 1].first--;
    vec[ans][0].first--;
    for (int i = int(1); i < int(n - 1); i++) {
      vec[ans][i].first -= 2;
    }
    int i = 0;
    while (i < n && vec[ans][i].first <= 0) i++;
    if (i == n) continue;
    int prev = vec[ans][i].second, cnt = vec[ans][i].first;
    for (i = i + 1; i < n; i++) {
      if (vec[ans][i].first <= 0) continue;
      int v = vec[ans][i].second;
      if (prev != v) {
        vec[ans + 1].push_back(pair<int, int>(cnt, prev));
        cnt = vec[ans][i].first;
        prev = v;
      } else
        cnt += vec[ans][i].first;
    }
    vec[ans + 1].push_back(pair<int, int>(cnt, prev));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(20);
  solve();
  return 0;
}
