#include <bits/stdc++.h>
using namespace std;
const int M = 1000010, mod = 1000000007;
struct evdata {
  int id, sz;
  evdata() {}
  evdata(int a, int b) {
    id = a;
    sz = b;
  }
};
struct data {
  int id, sz;
  data() {}
  data(int a, int b) {
    id = a;
    sz = b;
  }
  bool operator<(const data &d) const {
    if (id == d.id)
      return sz < d.sz;
    else
      return id < d.id;
  }
};
vector<evdata> E[M];
set<data> pos;
string a;
char let[M];
int __tt(int id, int sz) {
  int stid = pos.begin()->id;
  auto ee = pos.end();
  ee--;
  int edid = ee->id;
  if (id == stid || id == edid) return sz;
  return (sz + 1) / 2;
}
data Merge(data a, data b, int t) {
  data r;
  r.id = min(a.id, b.id);
  int stid = pos.begin()->id;
  auto ee = pos.end();
  ee--;
  int edid = ee->id;
  if (a.id == stid && b.id == edid) {
    a.sz -= t;
    b.sz -= t;
    r.sz = a.sz + b.sz + t;
  } else if (a.id == stid) {
    a.sz -= t;
    b.sz -= 2 * t;
    r.sz = a.sz + b.sz + t;
  } else if (b.id == edid) {
    a.sz -= 2 * t;
    b.sz -= t;
    r.sz = a.sz + b.sz + t;
  } else {
    a.sz -= 2 * t;
    b.sz -= 2 * t;
    r.sz = a.sz + b.sz + 2 * t;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k = 0;
  cin >> a;
  a += '$';
  int tmp = 1;
  for (i = 1; i < a.size(); i++) {
    if (a[i] == a[i - 1])
      tmp++;
    else {
      pos.insert(data(++k, tmp));
      let[k] = a[i - 1];
      tmp = 1;
    }
  }
  for (auto d : pos) E[__tt(d.id, d.sz)].push_back(evdata(d.id, d.sz));
  int last = 0;
  for (int t = 0; t < M; t++) {
    if (E[t].size() > 0) {
      for (evdata e : E[t]) {
        data cur = data(e.id, e.sz);
        auto it = pos.find(cur);
        if (it != pos.end()) {
          if (pos.size() > 1) {
            last = t;
          }
          if (pos.size() > 1) last = t;
          if (it != pos.begin()) {
            it++;
            auto nt = it;
            it--;
            if (nt != pos.end()) {
              it--;
              auto pt = it;
              it++;
              data nxt = *nt;
              data prv = *pt;
              if (let[nxt.id] == let[prv.id] && __tt(nxt.id, nxt.sz) > t &&
                  __tt(prv.id, prv.sz) > t) {
                data nw = Merge(prv, nxt, t);
                pos.erase(nxt);
                pos.erase(prv);
                pos.insert(nw);
                E[__tt(nw.id, nw.sz)].push_back(evdata(nw.id, nw.sz));
              }
              pos.erase(cur);
            }
          }
        }
      }
    }
  }
  printf("%d\n", last);
  return 0;
}
