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 op = 0;
        
        LinkedList<Integer> next = new LinkedList<Integer>();
        
        for(int i=0;i<n;i++) next.add(i);
        
        int pr = -1;
        boolean[] removed = new boolean[n];
        boolean ok = true;
        Iterator<Integer> it;
        int pos = 0;
        while(ok){
            ok = false;
            
            it = next.iterator();
            while(it.hasNext()){
                
                pos = it.next();
                if(nb[pos]==0) {
                    it.remove();
                    continue;
                }
                
                if(pr==-1){
                    pr = pos;
                    continue;
                }
                
                if(a[pr]==a[pos]){
                    
                    nb[pr] += nb[pos];
                    nb[pos] = 0;
                    it.remove();
                    removed[pr] = false;
                    
                    
                }else{
                    ok = true;
                    
                    if(!removed[pr]) {
                        nb[pr]--;
                    }
                    removed[pr] = false;
                    
                    nb[pos]--;
                    removed[pos] = true;
                    
                    pr = pos;
                    
                    if(nb[pos]==0) it.remove();
                    
                    
                }
                
            }
            if(pr!=-1) removed[pr] = false;
            if(ok) op++;
        }
        
        
        
        System.out.println(op);
        
        
    }
    
}