import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextLine();

            Node prevNode = new Node();

            Node parentNode = prevNode;

            char prevChar = s.charAt(0);
            prevNode.c = prevChar;
            int cnt = 1;

            for (int i = 1; i < s.length(); i++) {
                char curChar = s.charAt(i);
                if (prevChar == curChar) {
                    cnt++;
                } else {
                    prevNode.c = prevChar;
                    prevNode.cnt = cnt;

                    Node curNode = new Node();
                    prevNode.next = curNode;
                    curNode.prev = prevNode;

                    prevChar = curChar;
                    cnt = 1;
                }
            }

            if (prevNode.c == prevChar) {
                prevNode.cnt = cnt;
            } else {
                Node curNode = new Node();
                prevNode.next = curNode;
                curNode.prev = prevNode;
                curNode.c = prevChar;
                curNode.cnt = cnt;
            }

            int ans = 0;
            while (parentNode != null && parentNode.next != null) {
                for (Node node = parentNode; node != null; node = node.next) {

                    if (node.prev != null)
                        if (node.c != node.prev.c && node.cnt > 0)
                            node.cnt--;

                    if (node.next != null)
                        if (node.c != node.next.c && node.cnt > 0)
                            node.cnt--;
                }

                for (Node node = parentNode; node != null; node = node.next) {
                    while (node.next != null && node.c == node.next.c) {
                        node.cnt += node.next.cnt;

                        if (node.next.next != null)
                            node.next.next.prev = node;

                        node.next = node.next.next;
                    }
                }

                while (parentNode != null && parentNode.cnt == 0) {
                    if (parentNode.next == null) {
                        parentNode = null;
                    } else {
                        parentNode = parentNode.next;
                        parentNode.prev = null;
                    }
                }

                for (Node node = parentNode; node != null; node = node.next) {
                    if (node.next != null && node.next.cnt == 0) {

                        if (node.next.next != null)
                            node.next.next.prev = node;

                        node.next = node.next.next;
                    }
                }

                assert (parentNode == null || parentNode.cnt != 0);

                ans++;
            }

            out.println(ans);
        }

        class Node {
            public Node next;
            public Node prev;
            public char c;
            public int cnt;

        }

    }

    static class InputReader {
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String nextLine() {
            String str = null;
            try {
                str = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }

    }
}

