import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Solution {

    public static void solve(InputReader in, PrintWriter out, DebugWriter debug) throws IOException {
        String s = in.next();

        char nowColor = s.charAt(0);
        int firstThisColorPos = 0;
        ArrayList<Node> nodes = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != nowColor){
                nodes.add(new Node(nowColor, i-firstThisColorPos));
                nowColor = s.charAt(i);
                firstThisColorPos = i;
            }
        }
        nodes.add(new Node(nowColor, s.length()-firstThisColorPos));

        Node first = nodes.get(0);
        Node nowNode = first;
        for (int i = 1; i < nodes.size(); i++) {
            nowNode.next = nodes.get(i);
            nodes.get(i).last = nowNode;

            nowNode = nodes.get(i);
        }
        Node last = nowNode;

        int ans = 0;
        int size = nodes.size();
        while (true){
            if (size < 2) break;
            ans++;

            //Linking
            nowNode = first;
            do {
                if (nowNode.next != null && nowNode.color == nowNode.next.color){
                    nowNode.count += nowNode.next.count;
                    nowNode.next = nowNode.next.next;

                    nowNode = nowNode.next;
                }

                if (nowNode != null) nowNode = nowNode.next;
            } while (nowNode != null);

            nowNode = first;

            Node newFirst = null, newLast = null;
            do {
                if (nowNode == first) nowNode.count--;
                else if (nowNode == last) nowNode.count--;
                else nowNode.count -= 2;

                if (nowNode.count <= 0){
                    size--;

                    if (nowNode == first){
                        if (nowNode.next != null) nowNode.next.last = null;
                        newFirst = nowNode.next;
                    } else if (nowNode == last){
                        if (nowNode.last != null) nowNode.last.next = null;
                        newLast = nowNode.last;
                    } else {
                        if (nowNode.last != null) nowNode.last.next = nowNode.next;
                        if (nowNode.next != null)nowNode.next.last = nowNode.last;
                    }
                }

                nowNode = nowNode.next;
            } while (nowNode != null);

            if (newFirst != null) first = newFirst;
            if (newLast != null) last = newLast;
        }

        out.print(ans-1);
    }

    public static class Node{

        public Node next = null, last = null;
        public char color;
        public int count;

        public Node(char color, int count){
            this.color = color;
            this.count = count;
        }

    }

    public static final String NAME = "";

    public static void main(String[] args) throws IOException{
        InputReader in;
        PrintWriter out;
        DebugWriter debug;

        if (args.length > 0 && args[0].equals("file")) {
            in = new InputReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter(new FileWriter("output.txt"));
            debug = new DebugWriter(true);

            int sampleNumber = 1;
            do {
                String nextSample = "Sample #" + sampleNumber++ + ": ";
                out.println(nextSample);
                debug.println(nextSample);

                solve(in, out, debug);

                out.println("");
                debug.println("");
            } while (in.reader.readLine() != null);
        } else {
            if (NAME.length() > 0) {
                in = new InputReader(new BufferedReader(new FileReader(NAME + ".in")));
                out = new PrintWriter(new FileWriter(NAME + ".out"));
            } else {
                in = new InputReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            debug = new DebugWriter(false);
            solve(in, out, debug);
        }

        in.reader.close();
        out.close();
    }

    public static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(BufferedReader reader) {
            this.reader = reader;
            tokenizer = null;
        }

        public String next() throws IOException{
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }

            return tokenizer.nextToken();
        }

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

        public int[] nextIntArray(int n) throws IOException{
            int[] array = new int[n];
            for (int i=0; i<n; i++){
                array[i] = nextInt();
            }

            return array;
        }
    }

    public static class DebugWriter {
        public boolean enable;

        public DebugWriter(boolean enable){
            this.enable = enable;
        }

        public void print(Object o){
            if (enable) System.out.print(o);
        }

        public void println(Object o){
            if (enable) System.out.println(o);
        }
    }

}