import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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 last;
            int eliminated;
            ArrayList<TaskD.Point> toCheckNext;
            TaskD.Point next;
            while (toCheck.size() > 0) {
                eliminated = 0;

                last = toCheck.get(0).l;
                for (int i = 0; i < toCheck.size(); i++) {
                    next = toCheck.get(i);
                    if ((next.l != -1 && s.charAt(next.l) != s.charAt(next.i)) ||
                            (next.r != -1 && s.charAt(next.r) != s.charAt(next.i))) {
                        next.isOut = true;
                        eliminated++;

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

                last = toCheck.get(toCheck.size() - 1).r;
                for (int i = toCheck.size() - 1; i >= 0; i--) {
                    next = toCheck.get(i);
                    if ((next.l != -1 && s.charAt(next.l) != s.charAt(next.i)) ||
                            (next.r != -1 && s.charAt(next.r) != s.charAt(next.i))) {
                        next.isOut = true;

                        if (next.l != -1) points[next.l].nextR = last;
                    } else {
                        last = next.i;
                    }
                }

                toCheckNext = new ArrayList<>();
                for (int i = 0; i < toCheck.size(); i++) {
                    next = toCheck.get(i);

                    if (next.isOut) {
                        if (next.l != -1 && !points[next.l].isOut) {
                            toCheckNext.add(points[next.l]);
                            points[next.l].l = points[next.l].nextL;
                            points[next.l].r = points[next.l].nextR;
                        }
                        if (next.r != -1 && !points[next.r].isOut) {
                            toCheckNext.add(points[next.r]);
                            points[next.r].l = points[next.r].nextL;
                            points[next.r].r = points[next.r].nextR;
                        }
                    }
                }

                toCheck = toCheckNext;

                if (eliminated > 0) res++;
            }

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

        }

    }

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

    }
}

