#include <bits/stdc++.h>
using namespace std;
template <typename T, typename C>
ostream &operator<<(ostream &os, pair<T, C> x) {
  return os << "<" << x.first << ", " << x.second << ">";
}
template <typename T>
auto operator<<(ostream &os, T x) ->
    typename enable_if<is_same<decltype(x.begin()), decltype(x.end())>::value &&
                           !is_same<T, string>::value,
                       ostream &>::type {
  os << "{";
  int cou = 0;
  for (auto c : x) {
    if (cou++) os << ", ";
    os << c;
  }
  return os << "}";
}
template <typename T>
string strmask(T r) {
  string ans;
  for (int i = 0; i < (8 * (int)sizeof(T)); i++) {
    ans += '0' + !!(((T)1 << i) & r);
    if (i % 5 == 4) ans += '.';
  }
  return ans;
}
const int MN = 1e6 + 44;
char in[MN];
int l[MN], r[MN];
int pre(int x) {
  if (l[x] == x)
    return x;
  else
    return l[x] = pre(l[x]);
}
int nex(int x) {
  if (r[x] == x)
    return x;
  else
    return r[x] = nex(r[x]);
}
void rem(int x) {
  r[x] = x + 1;
  l[x] = x - 1;
}
vector<int> swaps[2];
void tryins(vector<int> &v, int x) {
  if (v.empty() || v.back() < x) v.push_back(x);
}
int main() {
  scanf("%s", in + 1);
  int n = strlen(in + 1);
  for (int i = 0; i < (n + 2); i++) l[i] = r[i] = i;
  for (int i = 1; i <= (n); i++) {
    if ((i != 1 && in[i - 1] != in[i]) || (i != n && in[i] != in[i + 1]))
      swaps[0].push_back(i);
  }
  int ans = 0;
  while (!swaps[0].empty()) {
    if (0)
      cout << "swaps[0]"
           << " = " << (swaps[0]) << ' ' << endl;
    ans++;
    for (int x : swaps[0]) rem(x);
    for (int x : swaps[0]) {
      int pr = pre(x), ne = nex(x);
      if (0)
        cout << "x"
             << " = " << (x) << ' ' << "pr"
             << " = " << (pr) << ' ' << "ne"
             << " = " << (ne) << ' ' << endl;
      if (pr != 0 && ne != n + 1 && in[pr] != in[ne]) {
        if (0) cout << "different " << endl;
        tryins(swaps[1], pr);
        tryins(swaps[1], ne);
      }
    }
    swap(swaps[0], swaps[1]);
    swaps[1].clear();
  }
  printf("%d\n", ans);
}
