import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created by makarfi on 12/28/17.
 */
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        char[] points = in.next().toCharArray();

        LinkedList<Point> set = new LinkedList<>();
        int ans = 0;

        for (int i = 1; i < points.length;) {
            int left = i-1, right = i;
            while (right < points.length && points[right] != points[right-1]) right++;

            if (right > left+1) set.add(new Point(left, right));

            i = Math.max(i+1, right);
        }

        boolean didUpdate = true;
        while (didUpdate) {
            if (!set.isEmpty()) ans++;

            LinkedList<Point> newSet = new LinkedList<>();
            LinkedList<Point> newList = new LinkedList<>();

            didUpdate = false;
            //merge ranges
            for (Point point: set) {
                if (!newSet.isEmpty() && point.left == newSet.getLast().right) {
                    newSet.getLast().right = point.right;
                } else {
                    newSet.addLast(new Point(point.left, point.right));
                }
            }

            //update ranges
            for (Point point: newSet) {
                int left = point.left-1, right = point.right;

                if (left >= 0 && right < points.length && points[left] != points[right]) {
                    didUpdate = true;
                    left--;
                    right++;

                    while (left >= 0 && points[left] != points[left+1]) left--;
                    while (right < points.length && points[right] != points[right-1]) right++;

                    newList.addLast(new Point(left, right));
                }

            }

            set = newList;
        }

        System.out.println(ans);
    }

    static class Point {
        int left, right;

        public Point(int left, int right) {
            this.left = left;
            this.right = right;
        }
    }
}
