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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
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) {
            String s = in.next();
            List<Pair> state = new ArrayList<>();
            char c = s.charAt(0);
            int count = 1;
            for (int i = 1; i < s.length(); i++) {
                if (s.charAt(i) == c) {
                    count++;
                } else {
                    state.add(new Pair(c, count));
                    c = s.charAt(i);
                    count = 1;
                }
            }
            state.add(new Pair(c, count));

            int result = 0;
            while (state.size() > 1) {
                int n = state.size();
                int min = state.get(0).amount;
                for (int i = 1; i < n - 1; i++) {
                    min = Math.min(min, (state.get(i).amount + 1) / 2);
                }
                min = Math.min(min, state.get(n - 1).amount);
                result += min;

                List<Pair> unmerged = new ArrayList<>();
                if (state.get(0).amount > min) {
                    unmerged.add(new Pair(state.get(0).color, state.get(0).amount - min));
                }
                for (int i = 1; i < n - 1; i++) {
                    if (state.get(i).amount > 2 * min) {
                        unmerged.add(new Pair(state.get(i).color, state.get(i).amount - 2 * min));
                    }
                }
                if (state.get(n - 1).amount > min) {
                    unmerged.add(new Pair(state.get(n - 1).color, state.get(n - 1).amount - min));
                }

                if (unmerged.size() == 0) {
                    break;
                }
                state = new ArrayList<>();
                Pair current = unmerged.get(0);
                for (int i = 1; i < unmerged.size(); i++) {
                    if (unmerged.get(i).color == current.color) {
                        current.amount += unmerged.get(i).amount;
                    } else {
                        state.add(current);
                        current = unmerged.get(i);
                    }
                }
                state.add(current);
            }
            out.println(result);
        }

        class Pair {
            int color;
            int amount;

            public Pair(int color, int amount) {
                this.color = color;
                this.amount = amount;
            }

        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                    //tok = new StringTokenizer(in.readLine(), ", \t\n\r\f"); //adds commas as delimeter
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}

