import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.TreeMap;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverse;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        solveD();
    }

    private void solveA() throws IOException {

    }

    private void solveB() throws IOException {

    }

    private void solveC() throws IOException {

    }

    class Group {
        char c;
        int k;

        Group(int i, char s) {
            c = s;
            k = i;
        }

        public String toString() {
            return c + "*" + k;
        }
    }

    private void solveD() throws IOException {
        char[] c = in.nextLine().toCharArray();
        int n = c.length;

        ArrayList<Group> g = new ArrayList<>();
        for (int i = 1, cnt = 1; i <= n; i++) {
            if (i < n && c[i] == c[i - 1])
                cnt++;
            else {
                g.add(new Group(cnt, c[i - 1]));
                cnt = 1;
            }
        }
        // out.println(Arrays.toString(g.toArray(new Group[g.size()])));

        ArrayList<Group> ng = new ArrayList<>();
        int ans = 0, min;
        while (g.size() > 1) {

            min = min(g.get(0).k, g.get(g.size() - 1).k);
            for (int i = 1; i + 1 < g.size(); i++) {
                min = min(min, (g.get(i).k + 1) / 2);
            }

            // out.println(min);

            g.get(0).k -= min;
            g.get(g.size() - 1).k -= min;
            for (int i = 1; i + 1 < g.size(); i++) {
                g.get(i).k -= min * 2;
            }

            // out.println(Arrays.toString(g.toArray(new Group[g.size()])));

            ng.clear();
            for (Group i : g) {
                if (i.k > 0)
                    ng.add(i);
            }
            g.clear();
            g.addAll(ng);

            // out.println(Arrays.toString(g.toArray(new Group[g.size()])));

            ng.clear();
            if (!g.isEmpty())
                ng.add(g.get(0));
            for (int i = 1; i < g.size(); i++) {
                if (g.get(i).c == ng.get(ng.size() - 1).c)
                    ng.get(ng.size() - 1).k += g.get(i).k;
                else
                    ng.add(g.get(i));
            }
            g.clear();
            g.addAll(ng);

            // out.println(Arrays.toString(g.toArray(new Group[g.size()])));

            ans += min;
        }
        out.println(ans);
    }

    private void solveE() throws IOException {

    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}
