import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

/**
 * Created by a_menkov on 27/12/17.
 */
public class C_455_B {
    public static void main(String[] args) {
        new C_455_B().run();
    }

    private void run() {
        try {
            Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            solve(in, out);
            out.flush();
        } catch (Exception e) {
            System.out.println("Error happened");
        }
    }

    private boolean can() {
        boolean result = false;
        for (int i = 0; i < len; i++) {
            if (i == 0) {
                if (s[i] != s[i + 1]) {
                    toDelete[i] = true;
                    result = true;
                } else {
                    toDelete[i] = false;
                }
            } else if (i == len - 1) {
                if (s[i] != s[i - 1]) {
                    toDelete[i] = true;
                    result = true;
                } else {
                    toDelete[i] = false;
                }
            } else {
                if (s[i] != s[i + 1] || s[i] != s[i - 1]) {
                    toDelete[i] = true;
                    result = true;
                } else {
                    toDelete[i] = false;
                }
            }
        }

        if (!result) return false;

        int newLen = 0;
        for (int i = 0; i < len; i++) {
            if (!toDelete[i]) {
                tmp[newLen++] = s[i];
            }
        }

        char[] p = tmp;
        tmp = s;
        s = p;
        len = newLen;

        return true;
    }

    int len;
    char[] s, tmp;
    boolean[] toDelete;

    static class Group {
        char ch;
        int count;
        boolean toDelete;
    }

    private void solve(Scanner in, PrintWriter out) {
        s = in.next().toCharArray();
        len = s.length;
        tmp = new char[len];
        toDelete = new boolean[len];
        boolean first = true;
        LinkedList<Group> l = new LinkedList<>();
        char lastCh = ' ';
        Group prevGroup = new Group();

        for (int i = 0; i < len; i++) {
            char curCh = s[i];
            if (first) {
                Group g = new Group();
                g.ch = curCh;
                g.count = 1;
                l.add(g);

                prevGroup = g;
                lastCh = curCh;
                first = false;
                continue;
            }

            if (curCh == lastCh) {
                prevGroup.count++;
                continue;
            }

            Group g = new Group();
            g.ch = curCh;
            g.count = 1;
            l.add(g);
            prevGroup = g;
            lastCh = curCh;
        }

        int result = 0;
        int count = countList(l);

        while (true) {
            decrement(l);
            merge(l);
            int newSize = countList(l);
            if (newSize == count) {
                out.println(result);
                return;
            }

            count = newSize;
            result++;
        }

    }

    int countList(LinkedList<Group> l) {
        int result = 0;
        for (Group g : l) result += g.count;
        return result;
    }

    void decrement(LinkedList<Group> l) {
//        if (l.size() < 2) return;

        ListIterator<Group> li = l.listIterator(0);
        while (li.hasNext()) {
            boolean hasPrevious = li.hasPrevious();
            Group g = li.next();
            boolean hasNext = li.hasNext();
            int newCount = g.count;
            if (hasPrevious) newCount--;
            if (hasNext) newCount--;
            g.count = Math.max(0, newCount);
        }

        li = l.listIterator(0);
        while (li.hasNext()) {
            Group g = li.next();
            if (g.count == 0) {
                li.remove();
            }
        }
    }

    void merge(LinkedList<Group> l) {
        ListIterator<Group> li = l.listIterator(0);
        while (li.hasNext()) {
            Group prev = null;
            if (li.hasPrevious()) {
                prev = li.previous();
                li.next();
            }
            Group g = li.next();
            if (prev != null) {
                if (g.ch == prev.ch) {
                    prev.count += g.count;
                    li.remove();
                }
            }
        }
    }

}
