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

/**
 * Created by Jarek on 2018-01-01.
 */
public class ColorFulPoints {

    private static class CharGroup {
        char character;
        int count;

        public CharGroup(char character, int count) {
            this.character = character;
            this.count = count;
        }

        public void inc() {
            count++;
        }

        public void decBy(int i) {
            count = count - i<0?0:count - i;

        }

        public void incBy(int i) {
            count = count + i;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String input = scanner.nextLine();
        //String input = "aaaaaaaaaaabbbbbbbbaa";
        char[] inputArr = input.toCharArray();
        List<CharGroup> groups = new ArrayList<>(inputArr.length);
        //build groups;
        CharGroup currentGroup = new CharGroup(inputArr[0], 1);
        groups.add(currentGroup);
        for (int i = 1; i < inputArr.length; i++) {
            if (inputArr[i - 1] == inputArr[i]) {
                currentGroup.inc();
            } else {
                currentGroup = new CharGroup(inputArr[i], 1);
                groups.add(currentGroup);
            }
        }

        int counter = 0;
        while (groups.size() > 1) {
            //get smallest group.
            int smallestGroup = -1;
            int minCount = Integer.MAX_VALUE;
            for (int i = 0; i < groups.size(); i++) {
                int count = (i == 0 || i == (groups.size() - 1)) ? groups.get(i).count : groups.get(i).count / 2;
                if (count == 0) {
                    count = 1;
                }
                if (count < minCount) {
                    minCount = count;
                    smallestGroup = i;
                }
            }

            //reduce group sizes
            for (int i = 0; i < groups.size(); i++) {
                if (i == 0 || i == groups.size() - 1) {
                    groups.get(i).decBy(minCount);
                } else {
                    groups.get(i).decBy(minCount * 2);
                }
            }

            //merge groups.
            List<CharGroup> mergedGroups = new ArrayList<>();
            int lastMergedGroup = 0, firstGroup = 0;
            for (int i = 0; i < groups.size(); i++) {
                if(groups.get(i).count > 0) {
                    mergedGroups.add(groups.get(i));
                    firstGroup = i;
                    break;
                }
            }
            for (int i = firstGroup+1; i < groups.size(); i++) {
                if (groups.get(i).count <= 0) continue;
                if (mergedGroups.get(lastMergedGroup).character == groups.get(i).character) {
                    mergedGroups.get(lastMergedGroup).incBy(groups.get(i).count);
                } else {
                    mergedGroups.add(groups.get(i));
                    lastMergedGroup++;
                }
            }
            groups = mergedGroups;
            counter += minCount;
        }

        System.out.println(counter);
    }
}
