/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    vector<pii> cur(sz(s));
    int sz = 0;
    for (int i = 0; i < sz(s); i++) {
        if (cur[sz].x && cur[sz].y == s[i])
            cur[sz].x++, cur[sz].y = s[i];
        else 
            cur[++sz].x++, cur[sz].y = s[i];
    }
    if (sz == 1)
        cout << 0, exit(0);
    vector<pii> New(sz);
    int ans = 0;
    while (1) {
        int pos = 0;
        for (int i = 1; i <= sz; i++) {
            if (i == 1 || i == sz)
                cur[i].x--;
            else
                cur[i].x -= 2;
            if (cur[i].x > 0) {
                if (pos && cur[i].y == New[pos].y) {
                    New[pos].x += cur[i].x;
                } else {
                    pos++; 
                    New[pos] = cur[i];    
                }                  
            }
        }
        sz = pos;
        for (int i = 0; i < pos; i++) 
            cur[i] = New[i];
        ans++;
        if (sz < 2)
            break;
    }
    cout << ans;   
    return false;                                                       
}