#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
const int N = 3e6 + 11;
int nex[N], pred[N], dd[N];
set<pair<int, int> > st;
vector<pair<int, char> > vv;
void del_(vector<int> v, int d) {
  for (int i = 0; i < v.size(); i++) {
    int nn = nex[v[i]];
    int pr = pred[v[i]];
    pred[nn] = pr;
    nex[pr] = nn;
    if (vv[nn].second == vv[pr].second && nn != 0 && pr != 0) {
      st.erase(make_pair(dd[pr], pr));
      st.erase(make_pair(dd[nn], nn));
      dd[nn] = max(0, vv[nn].first - 2 * d) + max(0, vv[pr].first - 2 * d);
      vv[nn].first = dd[nn];
      dd[nn] /= 2;
      dd[nn] += d;
      st.insert(make_pair(dd[nn], nn));
      pr = pred[pr];
      pred[nn] = pr;
      nex[pr] = nn;
      if (pred[nn] == 0 && nn != 0) {
        st.erase(make_pair(dd[nn], nn));
        dd[nn] = vv[nn].first - d;
        st.insert(make_pair(dd[nn], nn));
      }
      if (nex[pr] == 0 && pr != 0) {
        st.erase(make_pair(dd[pr], pr));
        dd[pr] = vv[pr].first - d;
        st.insert(make_pair(dd[pr], pr));
      }
    } else {
      if (pred[nn] == 0 && nn != 0) {
        st.erase(make_pair(dd[nn], nn));
        dd[nn] = vv[nn].first - d;
        st.insert(make_pair(dd[nn], nn));
      }
      if (nex[pr] == 0 && pr != 0) {
        st.erase(make_pair(dd[pr], pr));
        dd[pr] = vv[pr].first - d;
        st.insert(make_pair(dd[pr], pr));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vv.push_back(make_pair(-1, '-'));
  vv.push_back(make_pair(1, s[0]));
  for (int i = 1; i < s.size(); i++)
    if (s[i] == vv.back().second)
      vv.back().first++;
    else
      vv.push_back(make_pair(1, s[i]));
  if (vv.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 2; i < vv.size() - 1; i++) {
    dd[i] = (vv[i].first + 1) / 2;
    st.insert(make_pair(dd[i], i));
  }
  dd[1] = vv[1].first;
  st.insert(make_pair(vv[1].first, 1));
  st.insert(make_pair(vv.back().first, vv.size() - 1));
  dd[vv.size() - 1] = vv.back().first;
  int res = 0;
  for (int i = 1; i < vv.size(); i++) {
    pred[i] = i - 1;
    nex[i] = i + 1;
  }
  nex[vv.size() - 1] = 0;
  while (st.size() > 1) {
    pair<int, int> p = *st.begin();
    st.erase(p);
    vector<int> second;
    second.push_back(p.second);
    while (st.size() > 0) {
      pair<int, int> pp = *st.begin();
      if (pp.first != p.first) break;
      st.erase(pp);
      second.push_back(pp.second);
    }
    del_(second, p.first);
    res = p.first;
  }
  cout << res << endl;
}
