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];

        groupCounts[0] *= 2;
        groupCounts[nGroups-1] *= 2;

        int answer = 0;

        while (nGroups > 1) {
            int delete = Integer.MAX_VALUE;
            for (int i = 0; i < nGroups; i++)
                delete = Math.min(delete, (groupCounts[i] + 1) / 2 * 2);

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

            answer += delete / 2;
        }

        System.out.println(answer);
    }

}
