import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        char[] colors = new Scanner(System.in).next().toCharArray();

        int[] groupCounts = new int[colors.length];
        int[] groupColors = new int[colors.length];
        int nGroups = 0;

        int j = 0;
        for (int i = 0; i < colors.length; i++) {
            if (colors[i] != colors[j]) {
                groupCounts[nGroups] = i - j;
                groupColors[nGroups++] = colors[j];
                j = i;
            }
        }
        groupCounts[nGroups] = colors.length - j;
        groupColors[nGroups++] = colors[j];

        int answer = 0;

        while (nGroups > 1) {
            int operations = Integer.MAX_VALUE;
            for (int i = 0; i < nGroups; i++) {
                operations = Math.min(
                    operations, (i == 0 || i == nGroups-1) ? groupCounts[i] : (groupCounts[i] + 1) / 2
                );
            }

            for (int i = 0; i < nGroups; i++)
                groupCounts[i] -= ((i == 0 || i == nGroups - 1) ? operations : 2 * operations);

            j = 0;
            for (int i = 0; i < nGroups; i++) {
                if (groupCounts[i] > 0) {
                    if (groupColors[j] != groupColors[i]) {
                        if (groupCounts[j] > 0)
                            j++;
                        groupColors[j] = groupColors[i];
                        groupCounts[j] = groupCounts[i];
                    }
                    else if (j != i)
                        groupCounts[j] += groupCounts[i];
                }
            }
            nGroups = ++j;

            answer += operations;
        }

        System.out.println(answer);
    }

}
