#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool uin(T &a, T b) {
  return a > b && (a = b, true);
}
template <class T>
inline bool uax(T &a, T b) {
  return a < b && (a = b, true);
}
class DColorfulPoints {
 public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string s;
    cin >> s;
    int n = (int)s.length();
    vector<pair<int, char>> v;
    for (int i = 0, j = 0; i < n; i = j) {
      while (j < n && s[i] == s[j]) ++j;
      v.emplace_back(j - i, s[i]);
    }
    int ans = 0;
    while ((int)v.size() > 1) {
      vector<pair<int, char>> temp;
      for (int i = 0; i < (int)v.size() - 1; ++i) {
        --v[i].first;
        --v[i + 1].first;
      }
      for (auto &i : v) {
        if (i.first <= 0) continue;
        if (!temp.empty() && temp.back().second == i.second)
          temp.back().first += i.first;
        else
          temp.push_back(i);
      }
      v = temp;
      ++ans;
    }
    cout << ans << '\n';
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  DColorfulPoints solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
