#include <bits/stdc++.h>
using namespace std;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
unordered_map<long long int, long long int, chash> hashMap;
inline unsigned long long Rand(long long int a, long long int b) {
  uniform_int_distribution<uint64_t> dis(a, b);
  mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
  return dis(gen);
}
const long long int mod = 1e9 + 7;
void merge(std::vector<std::pair<long long int, long long int> > &a) {
  std::vector<std::pair<long long int, long long int> > x;
  for (auto i : a) {
    if (i.second != 0) {
      if (!x.empty() && x.back().first == i.first)
        x.back().second += i.second;
      else
        x.push_back(i);
    }
  }
  a = x;
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);
  ;
  string s;
  cin >> s;
  std::vector<std::pair<long long int, long long int> > a;
  long long int n = s.size(), j, cnt;
  for (int i = 0; i < n;) {
    j = i + 1, cnt = 1;
    while (j < n && s[j] == s[j - 1]) cnt++, ++j;
    a.push_back({s[i] - 'a', cnt});
    i = j;
  }
  long long int ans = 0;
  while (a.size() > 1) {
    n = a.size();
    std::vector<long long int> is(n, 0);
    a[0].second--;
    a[n - 1].second--;
    is[0] = a[0].second, is[n - 1] = a[n - 1].second;
    for (int i = 1; i < n - 1; ++i) {
      is[i] = (a[i].second < 3);
      a[i].second = max(0ll, a[i].second - 2);
    }
    merge(a);
    ++ans;
  }
  cout << ans << '\n';
  return 0;
}
