#include <bits/stdc++.h>
using namespace std;
struct Ch {
  char c;
  int n;
};
int ans;
void del(vector<Ch> v, int mn) {
  ans += mn;
  vector<Ch> w;
  for (int i = 0; i < (int)v.size(); i++) {
    if (i == 1 && i != (int)v.size() - 1)
      mn *= 2;
    else if (i == (int)v.size() - 1 && i != 1)
      mn /= 2;
    if (v[i].n > mn) {
      v[i].n -= mn;
      if (w.size() > 0) {
        if (w[(int)w.size() - 1].c == v[i].c)
          w[(int)w.size() - 1].n += v[i].n;
        else
          w.push_back(v[i]);
      } else
        w.push_back(v[i]);
    }
  }
  if (w.size() < 2) return;
  int newMin = w[0].n;
  for (int i = 0; i < (int)w.size() - 1; i++) {
    int n = w[i].n;
    if (n % 2 == 0)
      n = n / 2;
    else
      n = n / 2 + 1;
    newMin = min(newMin, n);
  }
  newMin = min(newMin, w[(int)w.size() - 1].n);
  if (w.size() > 1) del(w, newMin);
}
int main() {
  string s;
  cin >> s;
  vector<Ch> v;
  int n = 1;
  int m = (int)s.size();
  int mn = 1;
  ans = 0;
  for (int i = 1; i < m; i++) {
    if (s[i] == s[i - 1])
      n++;
    else {
      Ch ch;
      ch.c = s[i - 1];
      ch.n = n;
      v.push_back(ch);
      if (v.size() != 0) {
        if (n % 2 == 0)
          n = n / 2;
        else
          n = n / 2 + 1;
      }
      mn = min(mn, n);
      n = 1;
    }
  }
  Ch ch;
  ch.c = s[m - 1];
  ch.n = n;
  mn = min(mn, n);
  v.push_back(ch);
  if (v.size() == 1)
    cout << 0;
  else {
    del(v, mn);
    cout << ans;
  }
  return 0;
}
