#include <bits/stdc++.h>
using namespace std;
string DBG_DLM(int& i) { return (i++ == 0 ? "" : ", "); }
template <class T>
ostream& operator<<(ostream& os, vector<T> v);
template <class T>
ostream& operator<<(ostream& os, set<T> v);
template <class T>
ostream& operator<<(ostream& os, queue<T> q);
template <class T>
ostream& operator<<(ostream& os, priority_queue<T> q);
template <class T, class K>
ostream& operator<<(ostream& os, pair<T, K> p);
template <class T, class K>
ostream& operator<<(ostream& os, map<T, K> mp);
template <class T, class K>
ostream& operator<<(ostream& os, unordered_map<T, K> mp);
template <int I, class TPL>
void DBG(ostream& os, TPL t) {}
template <int I, class TPL, class H, class... Ts>
void DBG(ostream& os, TPL t) {
  os << (I == 0 ? "" : ", ") << get<I>(t);
  DBG<I + 1, TPL, Ts...>(os, t);
}
template <class T, class K>
void DBG(ostream& os, pair<T, K> p, string delim) {
  os << "(" << p.first << delim << p.second << ")";
}
template <class... Ts>
ostream& operator<<(ostream& os, tuple<Ts...> t) {
  os << "(";
  DBG<0, tuple<Ts...>, Ts...>(os, t);
  os << ")";
  return os;
}
template <class T, class K>
ostream& operator<<(ostream& os, pair<T, K> p) {
  DBG(os, p, ", ");
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
  {
    int i = 0;
    os << "{";
    {
      for (auto&& t : v) {
        os << DBG_DLM(i) << t;
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
ostream& operator<<(ostream& os, set<T> s) {
  {
    int i = 0;
    os << "{";
    {
      for (auto&& t : s) {
        os << DBG_DLM(i) << t;
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
ostream& operator<<(ostream& os, queue<T> q) {
  {
    int i = 0;
    os << "{";
    {
      for (; q.size(); q.pop()) {
        os << DBG_DLM(i) << q.front();
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
ostream& operator<<(ostream& os, priority_queue<T> q) {
  {
    int i = 0;
    os << "{";
    {
      for (; q.size(); q.pop()) {
        os << DBG_DLM(i) << q.top();
      };
    }
    os << "}";
    return os;
  };
}
template <class T, class K>
ostream& operator<<(ostream& os, map<T, K> m) {
  {
    int i = 0;
    os << "{";
    {
      for (auto&& p : m) {
        os << DBG_DLM(i);
        DBG(os, p, "->");
      };
    }
    os << "}";
    return os;
  };
}
template <class T, class K>
ostream& operator<<(ostream& os, unordered_map<T, K> m) {
  {
    int i = 0;
    os << "{";
    {
      for (auto&& p : m) {
        os << DBG_DLM(i);
        DBG(os, p, "->");
      };
    }
    os << "}";
    return os;
  };
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vvvpii = vector<vvpii>;
template <class A, class B>
bool amax(A& a, const B& b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B>
bool amin(A& a, const B& b) {
  return b < a ? a = b, 1 : 0;
}
ll ri() {
  ll l;
  cin >> l;
  return l;
}
string rs() {
  string s;
  cin >> s;
  return s;
}
struct LST {
  const int n;
  const int d;
  vector<vector<uint64_t>> seg;
  int count = 0;
  LST(int _n) : n(_n ? _n : 1), d(calcd(_n)), seg(d) {
    for (int i = 0, m = n >> 6; i < d; m >>= 6) {
      seg[i++].resize(m + 1);
    }
  }
  bool empty() const { return seg.back()[0] != 0; }
  int size() const { return count; }
  bool get(int pos) const {
    return pos >= 0 && pos < n && (seg[0][pos >> 6] & (1LL << (pos & 63)));
  }
  void set(int pos) {
    if (get(pos)) return;
    count++;
    if (pos >= 0 && pos < n) {
      for (int i = 0; i < d; i++) {
        seg[i][pos >> 6] |= 1LL << pos;
        pos >>= 6;
      }
    }
  }
  void unset(int pos) {
    if (!get(pos)) return;
    count--;
    if (pos >= 0 && pos < n) {
      for (int i = 0; i < d && (i == 0 || seg[i - 1][pos] == 0L); pos >>= 6) {
        seg[i][pos >> 6] &= ~(1LL << pos);
        i++;
      }
    }
  }
  void set_range(int r) {
    for (int i = 0; i < d; i++, r = (r + 63) >> 6) {
      for (int j = 0; j < r >> 6; j++) {
        seg[i][j] = -1;
      }
      if ((r & 63) != 0) seg[i][r >> 6] |= (1L << r) - 1;
    }
  }
  void unset_range(int r) {
    if (r >= 0) {
      for (int i = 0; i < d; i++, r = (r + 63) >> 6) {
        for (int j = 0; j < (r + 63) >> 6; j++) {
          seg[i][j] = 0;
        }
        if ((r & 63) != 0) seg[i][r >> 6] &= ~((1LL << r) - 1);
      }
    }
  }
  int next(int pos) const {
    for (int i = 0; i < d && pos >> 6 < (int)seg[i].size();
         i++, pos >>= 6, pos++) {
      int nex = next(seg[i][pos >> 6], pos & 63);
      if (nex != -1) {
        pos = pos >> 6 << 6 | nex;
        while (i > 0) pos = pos << 6 | __builtin_ctzll(seg[--i][pos]);
        return pos;
      }
    }
    return -1;
  }
  int prev(int pos) const {
    for (int i = 0; i < d && pos >= 0; i++, pos >>= 6, pos--) {
      int pre = prev(seg[i][pos >> 6], pos & 63);
      if (pre != -1) {
        pos = ((pos >> 6) << 6) | pre;
        while (i > 0) pos = pos << 6 | 63 - __builtin_clzll(seg[--i][pos]);
        return pos;
      }
    }
    return -1;
  }

 private:
  static int calcd(int n) {
    int d = 0;
    for (int m = n; m > 1; m >>= 6) {
      d++;
    }
    return d;
  }
  static int next(uint64_t seg, int n) {
    uint64_t h = seg >> n;
    h &= -h;
    if (h == 0) return -1;
    return __builtin_ctzll(h) + n;
  }
  static int prev(uint64_t seg, int n) {
    uint64_t segn = seg << (63 - n);
    if (segn == 0) return -1;
    return (63 - __builtin_clzll(segn)) - (63 - n);
  }
};
ostream& operator<<(ostream& os, const LST& lst) {
  vector<int> vec;
  for (int pos = lst.next(0); pos != -1; pos = lst.next(pos + 1)) {
    vec.emplace_back(pos);
  }
  os << vec;
  return os;
}
ll solve() {
  auto s = rs();
  int n = ((int)(s).size());
  ;
  LST lst(n);
  lst.set_range(n);
  queue<int> q;
  for (int i = int(0); i < int(n); ++i) q.emplace(i);
  vi erase(n * 3 + 5);
  for (int i = int(0); i < int(n); ++i) {
    queue<int> nq;
    int p = 0;
    while (((int)(q).size())) {
      int cur = q.front();
      q.pop();
      if (!lst.get(cur)) continue;
      int nex = lst.next(cur + 1);
      int pre = lst.prev(cur - 1);
      if (nex != -1 && s[cur] != s[nex]) {
        erase[p++] = cur;
        if (pre != -1) nq.emplace(pre);
      } else if (pre != -1 && s[cur] != s[pre]) {
        erase[p++] = cur;
        if (nex != -1) nq.emplace(nex);
      }
    }
    for (int j = 0; j < p; j++) {
      lst.unset(erase[j]);
    }
    if (p == 0) {
      return i;
    }
    q = nq;
  }
  assert(false);
}
void Main() { cout << solve() << endl; }
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Main();
  return 0;
}
