import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static sun.nio.ch.IOStatus.check;

public class D {

    static class Node{
        char color;
        Node next;
        Node prev;
        boolean remove;
        boolean header;
    }

    public static void main(String[] args) {

        PrintWriter out = new PrintWriter(System.out);
        MyScanner in = new MyScanner();

        String s = in.next();

        Node prev = null;

        List<Node> toRemove = new ArrayList<>();

        for(int i=0;i<s.length();++i){
            Node node = new Node();
            node.color = s.charAt(i);
            if(prev!=null) {
                prev.next = node;
            }
            node.prev = prev;

            if(i>0 && prev.color != node.color){
                toRemove.add(node);
                node.remove = true;
                if(!prev.remove){
                    prev.remove = true;
                    toRemove.add(prev);
                }
            }
            prev = node;
        }

        int result = 0;
        while(toRemove.size()>0){
            List<Node> candidates = new ArrayList<>();
            result++;
            for(Node node:toRemove){
                Node next = node.next;
                prev = node.prev;

                if(next!=null){
                    next.prev = prev;
                }
                if(prev!=null){
                    prev.next = next;
                }
                if(prev!=null && next!=null){
                    if(!prev.remove && !next.remove && prev.color!=next.color){
                        candidates.add(prev);
                        candidates.add(next);
                    }
                }
            }
            for(Node node: candidates){
                node.remove = true;
            }
            toRemove = candidates;
        }
        out.println(result);
        out.close();
    }


    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    // --------------------------------------------------------


}
