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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] a = in.readLine().toCharArray();
            int n = a.length;

            ArrayList<Integer> group = new ArrayList<>();
            int i, j;
            for (i = 0, j = 0; i < n; i++) {
                if (a[i] != a[j]) {
                    group.add(a[j] - 'a');
                    group.add(i - j);
                    j = i;
                }
            }
            group.add(a[n - 1] - 'a');
            group.add(i - j);

            int ans = 0;
            while (group.size() > 2) {
                ArrayList<Integer> nq = new ArrayList<>();
                int total = 0;
                for (int p = 0; p < group.size(); p += 2) {
                    int col = group.get(p);
                    int cnt = group.get(p + 1);
                    if (p == 0 || p == group.size() - 2) cnt--;
                    else cnt -= 2;

                    if (cnt <= 0) continue;
                    if (nq.size() > 0 && nq.get(nq.size() - 2) == col) {
                        nq.set(nq.size() - 1, nq.get(nq.size() - 1) + cnt);

                    } else {
                        nq.add(col);
                        nq.add(cnt);
                        total++;
                    }
                }
                group = nq;
                ans++;
                if (total <= 1) break;
            }
            out.println(ans);
        }

    }

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

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

        public 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++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}

