import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
    
    
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        
        //PrintWriter out = new PrintWriter(System.out);
        
        //n = Integer.parseInt(st.nextToken());
        String s = new String();
        s = br.readLine();
        int n = s.length();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = s.charAt(i)-'a';
        }
        
        int[] nb = new int[n];
        Arrays.fill(nb,1);
        
        int[] next = new int[n];
        for(int i=0;i<n;i++){
            next[i] = i+1;
        }
        
        boolean ok = true;
        int op = 0;
        int pos = 0;
        boolean[] op_finiched = new boolean[n];
        int first = 0;
        int pr = 0;
        while(ok){
            ok = false;
            pos = first;
            pr = first;
            while(next[pos]!=n){
                
                if(a[next[pos]]!=a[pos]){
                    
                    if(!op_finiched[pos]){
                        nb[pos]--;
                        op_finiched[pos] = true;
                    }
                    
                    if(nb[pos]!=0) pr = pos;
                    
                    nb[next[pos]]--;
                    op_finiched[next[pos]] = true;
                    if(nb[pos]==0 && first==pos) first = next[pos];
                    
                    
                    op_finiched[pos] = false;
                    pos = next[pos];
                    ok = true;
                    
                    if(nb[pos]==0) {
                        next[pr] = next[pos];
                    }
                    
                }else{
                    
                    nb[next[pos]] += nb[pos];
                    nb[pos] = 0;
                    op_finiched[pos] = false;
                    if(first==pos) first = next[pos];
                    pos = next[pos];
                    
                    if(nb[pos]!=0) pr = pos;
                    
                }
                
            }
            
            op_finiched[pos] = false;
            
            if(ok) op++;
        }
        
        System.out.println(op);
        
        
    }
    
}