#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long INF = (1ll << 63) - 1ll;
const long double INFd = 28e14;
const long long inf = (1 << 31) - 1;
const long double EPS = 1e-8;
const long double PI = acos(-1.0);
using namespace std;
void OUT(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Out(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void out(bool f) {
  if (f)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
inline int next_rand() { return abs(rand() * rand() + rand()); }
struct __debug__ {
  __debug__(string filename, bool f = false) {
    if (filename == "") return;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string filein = filename + ".in";
    string fileout = filename + ".out";
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  ~__debug__() {}
};
__debug__ DEBUG("");
void gen();
void solve();
int main() {
  srand('M' + 'A' + 'S' + 'L' + '0' + 'F');
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
string h;
vector<pair<char, int>> v, vv;
void solve() {
  cin >> h;
  v.push_back(make_pair(h[0], 0));
  for (auto i : h) {
    if (v.back().first == i)
      v.back().second += 1;
    else
      v.push_back(make_pair(i, 1));
  }
  int ans = 0;
  while (!v.empty() && v.size() != 1) {
    int mx = 0;
    for (int i = 1; i + 1 < v.size(); ++i) mx = max(mx, v[i].second);
    if (v.size() == 2) {
      ans += min(v[0].second, v[1].second);
      break;
    }
    int dlt = min(v[0].second, v.back().second);
    dlt = min(dlt, (mx + 1) / 2);
    ans += dlt;
    for (int i = 0; i < v.size(); ++i) v[i].second -= dlt * 2;
    v[0].second += dlt;
    v.back().second += dlt;
    vv.clear();
    for (auto i : v) {
      if (i.second > 0) {
        if (vv.empty())
          vv.push_back(i);
        else if (vv.back().first == i.first)
          vv.back().second += i.second;
      }
    }
    swap(v, vv);
  }
  cout << ans << endl;
}
