import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class D909 {
        int N;
        char[] inp;

        int[][] compress(int[][] dat) {
            // first thing gets 1 cut off the right
            boolean any = false;
            int first = -9;
            N = dat.length;
            dat[0][1]--;
            any |= dat[0][1] > 0;
            if (any) first = 0;
            for (int i = 1; i < N; i++) {
                dat[i][1] -= i == N - 1 ? 1 : 2;
                if (!any) {
                    any = dat[i][1] > 0;
                    if (any)
                        first = i;
                }
            }

            if (!any) return new int[0][2];

            // string new things together
            ArrayList<int[]> ret = new ArrayList<>();
            int last = dat[first][0];
            int run = dat[first][1];
            for (int i = first + 1; i < N; i++) {
                if (dat[i][1] <= 0) continue;
                if (dat[i][0] == last)
                    run += dat[i][1];
                else {
                    ret.add(new int[]{last, run});
                    run = dat[i][1];
                    last = dat[i][0];
                }
            }

            ret.add(new int[]{last, run});

            int[][] rat = new int[ret.size()][];
            int ind = 0;
            for (int[] i : ret)
                rat[ind++] = i;

            return rat;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {
            inp = s.next().toCharArray();
            N = inp.length;

            ArrayList<int[]> next = new ArrayList<>();
            int last = inp[0];
            int run = 1;
            for (int i = 1; i < inp.length; i++) {
                if (inp[i] == last) run++;
                else {
                    next.add(new int[]{last, run});
                    run = 1;
                    last = inp[i];
                }
            }
            next.add(new int[]{last, run});

            int[][] dat = new int[next.size()][];
            int ind = 0;
            for (int[] i : next)
                dat[ind++] = i;

            int answer = 0;
            while (dat.length > 1) {
                answer++;
                dat = compress(dat);
            }

            out.println(answer);

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}

