#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool cmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool cmin(T &a, const U &b) {
  return b < a ? a = b, 1 : 0;
}
void _BG(const char *s) { cerr << s << endl; };
template <class T, class... TT>
void _BG(const char *s, T a, TT... b) {
  for (int c = 0; *s && (c || *s != ','); ++s) {
    cerr << *s;
    for (char x : "([{") c += *s == x;
    for (char x : ")]}") c -= *s == x;
  }
  cerr << " = " << a;
  if (sizeof...(b)) {
    cerr << ", ";
    ++s;
  }
  _BG(s, b...);
}
bool RD() { return 1; }
bool RD(char &a) { return scanf(" %c", &a) == 1; }
bool RD(char *a) { return scanf("%s", a) == 1; }
bool RD(double &a) { return scanf("%lf", &a) == 1; }
bool RD(int &a) { return scanf("%d", &a) == 1; }
bool RD(long long &a) { return scanf("%lld", &a) == 1; }
template <class T, class... TT>
bool RD(T &a, TT &...b) {
  return RD(a) && RD(b...);
}
void PT(const char &a) { putchar(a); }
void PT(char const *const &a) { fputs(a, stdout); }
void PT(const double &a) { printf("%.16f", a); }
void PT(const int &a) { printf("%d", a); }
void PT(const long long &a) { printf("%lld", a); }
template <char s = ' ', char e = '\n'>
void PL() {
  if (e) PT(e);
}
template <char s = ' ', char e = '\n', class T, class... TT>
void PL(const T &a, const TT &...b) {
  PT(a);
  if (sizeof...(b) && s) PT(s);
  PL<s, e>(b...);
}
struct node {
  static node *nil;
  node *p, *c[2], *mn;
  int k, v;
  node(int a, int b) : p(nil), c{nil, nil}, mn(this), k(a), v(b) {}
  node *pull() {
    if (this == nil) return this;
    mn = this;
    for (int i(0); i < (2); ++i)
      if (c[i]->mn->v < mn->v) mn = c[i]->mn;
    return this;
  }
  int d() { return p->c[1] == this; }
  void lk(int i, node *x) {
    c[i] = x;
    x->p = this;
  }
  node *cc(int i) {
    node *x = c[i];
    lk(i, nil);
    nil->lk(0, x);
    this->pull();
    return x;
  }
  node *rot() {
    int i = d();
    node *x = p;
    p->lk(i, c[i ^ 1]);
    p->pull();
    p->p->lk(p->d(), this);
    lk(i ^ 1, x);
    return this;
  }
  node *spl() {
    for (; p != nil; rot())
      if (p->p != nil) (p->d() == d() ? p : this)->rot();
    return this->pull();
  }
  node *la() { return c[1] != nil ? c[1]->la() : this->spl(); }
  node *fi() { return c[0] != nil ? c[0]->fi() : this->spl(); }
};
node *node::nil = new node(-1, 1e9 + 987);
int ans;
node *meld(node *a, node *b) {
  if (a == node::nil) return b;
  if (b == node::nil) return a;
  a = a->la();
  b = b->fi();
  if (a->k == b->k) {
    a->v += b->v - 2 * ans;
    node *t = b->cc(1);
    delete b;
    b = t;
  }
  a->lk(1, b);
  return a->pull();
}
node *rm(node *t) {
  if (t == node::nil) return t;
  t = t->mn->spl();
  if (t->v <= 2 * ans) {
    node *x = meld(rm(t->cc(0)), rm(t->cc(1)));
    delete t;
    t = x;
  }
  return t;
}
int main() {
  node *b, *t, *e;
  b = t = e = node::nil;
  {
    vector<pair<int, int> > a;
    char c;
    while (RD(c)) {
      c -= 'a';
      if (!((int)(a).size()) || ((a).back()).first != c)
        a.push_back({c, 1});
      else
        ++((a).back()).second;
    }
    b = new node(a[0].first, a[0].second);
    int i = 1;
    for (; i < ((int)(a).size()) - 1; ++i)
      t = meld(t, new node(a[i].first, a[i].second));
    if (i < ((int)(a).size())) e = new node(a[i].first, a[i].second);
  }
  while (b != node::nil && e != node::nil) {
    if (t != node::nil) {
      t = t->mn->spl();
      int k = min((t->v - 2 * ans + 1) / 2, min(b->v, e->v));
      ans += k;
      t = rm(t);
      if ((b->v -= k) == 0) {
        delete b;
        b = node::nil;
        if (t != node::nil) {
          b = t->fi();
          t = b->cc(1);
          b->v -= 2 * ans;
        }
      }
      if ((e->v -= k) == 0) {
        delete e;
        e = node::nil;
        if (t != node::nil) {
          e = t->la();
          t = e->cc(0);
          e->v -= 2 * ans;
        }
      }
      if (b != node::nil && t != node::nil && (t = t->fi())->k == b->k) {
        b->v += t->v - 2 * ans;
        node *x = t->cc(1);
        delete t;
        t = x;
      }
      if (e != node::nil && t != node::nil && (t = t->la())->k == e->k) {
        e->v += t->v - 2 * ans;
        node *x = t->cc(0);
        delete t;
        t = x;
      }
    } else {
      ans += min(b->v, e->v) * (b->k != e->k);
      e = node::nil;
    }
  }
  PL(ans);
}
