import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class _909D {

    private static class Node {
        final char color;
        Node prev;
        Node next;
        boolean dying;

        Node(char color) {
            this.color = color;
        }
    }

    private static void solve(Scanner scan, PrintWriter pw) {
        String colors = scan.nextLine();

        Node prev = new Node(colors.charAt(0));
        Queue<Node> dyingNodes = new LinkedList<>();

        for(int i = 1; i < colors.length(); i++) {
            Node node = new Node(colors.charAt(i));
            node.prev = prev;
            prev.next = node;

            if(node.color != prev.color) {
                if(!prev.dying) {
                    prev.dying = true;
                    dyingNodes.offer(prev);
                }
                node.dying = true;
                dyingNodes.offer(node);
            }

            prev = node;
        }

        Queue<Node> possibleDyingNodes = new LinkedList<>();

        int numOperations = 0;

        while(!dyingNodes.isEmpty()) {

            numOperations++;

            for (Node dying : dyingNodes) {
                if (dying.prev != null && !dying.prev.dying)
                    possibleDyingNodes.offer(dying.prev);
                if (dying.next != null && !dying.next.dying)
                    possibleDyingNodes.offer(dying.next);
            }

            while (!dyingNodes.isEmpty()) {
                Node dying = dyingNodes.poll();
                if (dying.prev == null && dying.next != null) {
                    dying.next.prev = null;
                } else if (dying.prev != null && dying.next == null) {
                    dying.prev.next = null;
                } else if (dying.prev != null) {
                    dying.prev.next = dying.next;
                    dying.next.prev = dying.prev;
                }

                dying.next = null;
                dying.prev = null;
            }

            while (!possibleDyingNodes.isEmpty()) {
                Node possibleDying = possibleDyingNodes.poll();
                if (possibleDying.prev != null && possibleDying.color != possibleDying.prev.color ||
                        possibleDying.next != null && possibleDying.color != possibleDying.next.color) {
                    possibleDying.dying = true;
                    dyingNodes.offer(possibleDying);
                }
            }
        }

        System.out.println(numOperations);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 64));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 1024 * 64));
        solve(scan, pw);
        pw.flush();
    }

}