import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Liavontsi Brechka
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static
    @SuppressWarnings("Duplicates")
    class TaskD {
        static int n;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            n = s.length();
            TaskD.Point[] points = new TaskD.Point[n];

            ArrayList<TaskD.Point> toCheck = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                points[i] = new TaskD.Point(i);
                toCheck.add(points[i]);
            }

            int res = 0;

            int eliminated;
            int last;
            ArrayList<TaskD.Point> toCheckNext;
            boolean[] leftCheck, rightCheck;
            while (toCheck.size() > 0) {
                toCheckNext = new ArrayList<>();
                leftCheck = new boolean[n];
                rightCheck = new boolean[n];
                eliminated = 0;

                last = -1;
                for (TaskD.Point next : toCheck) {
                    if ((next.l != -1 && s.charAt(next.i) != s.charAt(next.l)) ||
                            (next.r != -1 && s.charAt(next.i) != s.charAt(next.r))) {
                        next.isOut = true;
                        eliminated++;

                        if (next.r != -1) {
                            points[next.r].nextL = last;
                            leftCheck[next.r] = true;
                        }
                        if (next.l != -1) leftCheck[next.l] = true;
                    } else {
                        last = next.i;
                    }
                }

                last = -1;
                TaskD.Point next;
                for (int i = toCheck.size() - 1; i >= 0; i--) {
                    next = toCheck.get(i);

                    if ((next.l != -1 && s.charAt(next.i) != s.charAt(next.l)) ||
                            (next.r != -1 && s.charAt(next.i) != s.charAt(next.r))) {
                        if (next.l != -1) {
                            points[next.l].nextR = last;
                            rightCheck[next.l] = true;
                        }
                        if (next.r != -1) rightCheck[next.r] = true;
                    } else {
                        last = next.i;
                    }
                }

                for (int i = 0; i < toCheck.size(); i++) {
                    next = toCheck.get(i);
                    if (!next.isOut && (leftCheck[next.i] || rightCheck[next.i])) {
                        toCheckNext.add(next);
                        next.l = next.nextL;
                        next.r = next.nextR;
                    }
                }

                if (eliminated == 0) break;

                res++;
                toCheck = toCheckNext;
            }

            out.print(res);
        }

        private static class Point {
            int i;
            int l;
            int r;
            int nextL;
            int nextR;
            boolean isOut;

            public Point(int i) {
                this.i = i;
                nextL = l = i - 1;
                nextR = r = i + 1 >= n ? -1 : i + 1;
                isOut = false;
            }


            public boolean equals(Object o) {
                if (this == o) return true;
                if (o == null || getClass() != o.getClass()) return false;
                TaskD.Point point = (TaskD.Point) o;
                return i == point.i;
            }


            public int hashCode() {
                return Objects.hash(i);
            }

        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

