import java.util.ArrayList;
import java.util.Scanner;

public class D {

    private static class Point {
        char color;
        int count;

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

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String pointsAsString = s.next();
        ArrayList<Point> points = new ArrayList<>();
        Character prevChar = null;
        for (char c : pointsAsString.toCharArray()) {
            if (new Character(c).equals(prevChar)) {
                points.get(points.size() - 1).count++;
            } else {
                points.add(new Point(c, 1));
            }
            prevChar = c;
        }

        int loops = 0;
        while (points.size() > 1) {
            for (int i = 1; i < points.size(); ++i) points.get(i).count--;
            for (int i = 0; i < points.size() - 1; ++i) points.get(i).count--;
            ArrayList<Point> updatedPoints = new ArrayList<>();
            for (Point point : points) {
                if (point.count <= 0) continue;
                if (updatedPoints.size() > 0 && updatedPoints.get(updatedPoints.size()-1).color == point.color) {
                    updatedPoints.get(updatedPoints.size()-1).count += point.count;
                } else {
                    updatedPoints.add(point);
                }
            }
            points = updatedPoints;
            ++loops;
        }

        System.out.println(loops);
    }
}
