#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int mark[3000005];
int main() {
  string t;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, j;
  while (cin >> t) {
    set<long long int> s, b;
    for (i = 0; i < t.size(); i++) s.insert(i);
    for (i = 0; i + 1 < t.size(); i++) {
      if (t[i] != t[i + 1]) {
        b.insert(i);
      }
    }
    long long int cn = 0;
    set<long long int>::iterator it;
    s.insert(-1);
    s.insert(t.size());
    while (b.size() > 0) {
      vector<long long int> v;
      cn++;
      while (b.size() > 0) {
        long long int r = *b.begin();
        b.erase(b.find(r));
        if (mark[r] == 1) continue;
        s.erase(s.find(r));
        mark[r] = 1;
        while (1) {
          long long int r1 = *s.upper_bound(r);
          if (r1 == t.size()) break;
          if (t[r] == t[r1]) {
            v.push_back(r1);
            break;
          }
          mark[r1] = 1;
          s.erase(s.find(r1));
          r = r1;
        }
      }
      for (i = 0; i < v.size(); i++) {
        if (mark[v[i]] == 1) continue;
        it = s.lower_bound(v[i]);
        if (*it >= v[i]) it--;
        long long int x = *it;
        if (x == -1 || mark[x] == 1) continue;
        if (t[x] != t[v[i]]) b.insert(x);
      }
    }
    cout << cn << endl;
  }
  return 0;
}
