#include <bits/stdc++.h>
using namespace std;
struct GG {
  int num;
  int c;
  int polg;
  GG(int a, int b, int cc) {
    num = a;
    c = b;
    polg = cc;
  }
};
string s;
inline int min(int a, int b) { return a < b ? a : b; }
bool operator<(GG a, GG b) { return a.polg < b.polg; }
set<GG> v;
set<GG> vt;
int main() {
  cin >> s;
  int op = 0;
  int mx = 10000000;
  int con = 1, cnt = 0;
  for (int i = 1; s[i] != '\0'; i++) {
    if (s[i] == s[i - 1])
      con++;
    else {
      v.insert(GG(con, s[i - 1] - 'a' + 1, ++cnt));
      int mun = (v.size() != 1) ? con / 2 + con % 2 : con;
      con = 1;
      mx = min(mx, mun);
    }
  }
  v.insert(GG(con, s[s.size() - 1] - 'a' + 1, ++cnt));
  mx = min(mx, con);
  while (v.size() > 1) {
    op = op + mx;
    vt.erase(vt.begin(), vt.end());
    cnt = 0;
    for (set<GG>::iterator it = v.begin(); it != v.end(); it++) {
      GG q = *it;
      set<GG>::iterator it2 = it;
      it2++;
      int mun = ((it == v.begin() || it2 == v.end()) ? mx : mx * 2);
      q.num = q.num - mun;
      if (q.num > 0) {
        vt.insert(GG(q.num, q.c, ++cnt));
      }
    }
    cnt = 0;
    v.erase(v.begin(), v.end());
    mx = 1000000;
    if (vt.size() == 0 || vt.size() == 1) break;
    bool flg = 1;
    for (set<GG>::iterator it = vt.begin(); it != vt.end();) {
      GG q = *it;
      it++;
      GG q2 = *it;
      int numm = q.num;
      while (it != vt.end() && q.c == q2.c) {
        it++;
        q = q2;
        q2 = *it;
        numm += q.num;
      }
      v.insert(GG(numm, q.c, ++cnt));
      if (flg || it == vt.end()) {
        mx = min(mx, numm);
      } else
        mx = min(mx, numm / 2 + numm % 2);
      flg = 0;
    }
  }
  printf("%d\n", op);
  return 0;
}
