#include <bits/stdc++.h>
using namespace std;
string s;
vector<pair<char, int> > g(1000001), g1(1000001);
int n, nr, N;
int main() {
  cin >> s;
  n = s.length();
  N = 1;
  g[N] = make_pair(s[0], 1);
  for (int i = 1; i < n; i++) {
    if (s[i] == g[N].first)
      g[N].second += 1;
    else {
      N = N + 1;
      g[N] = make_pair(s[i], 1);
    }
  }
  nr = 0;
  while (N > 1) {
    int minop = 1e6;
    for (int i = 1; i <= N; i++)
      if (i == 1 or i == N) {
        if (minop > g[i].second) minop = g[i].second;
      } else if (minop > (g[i].second + 1) / 2)
        minop = (g[i].second + 1) / 2;
    nr = nr + minop;
    for (int i = 1; i <= N; i++)
      if (i == 1 or i == N)
        g[i].second -= minop;
      else
        g[i].second -= 2 * minop;
    int N1 = 0;
    for (int i = 1; i <= N; i++)
      if (g[i].second > 0) {
        N1 = N1 + 1;
        g1[N1] = g[i];
      }
    N = 0;
    if (N1 > 0) {
      N = 1;
      int j = 1;
      while (g1[j].second < 1) j = j + 1;
      g[N] = g1[j];
      for (int i = j + 1; i <= N1; i++) {
        if (g1[i].first == g[N].first)
          g[N].second += g1[i].second;
        else {
          N = N + 1;
          g[N] = g1[i];
        }
      }
    }
  }
  cout << nr;
  return 0;
}
