import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Main {
    public static void main(String[] args) {
        List<CharOccurence> s = new LinkedList<CharOccurence>();
        int pr = '-';
        int cur = 0;
        int mn = Integer.MAX_VALUE;
        int c = -2;
        while (c != -1) {
            try {
                c = System.in.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (pr != c && pr != '-' && pr != '\n' && pr != '\r') {
                s.add(new CharOccurence(pr, cur));
                mn = Math.min(mn, (int) Math.ceil(cur/2.0));
                cur = 0;
            }
            pr = c;
            cur ++;
        }
        long res = 0;
        while (s.size() > 1) {
            res += mn;
            ListIterator<CharOccurence> iter = s.listIterator();
            CharOccurence prev = null;
            while (iter.hasNext()) {
                boolean flag = true;
                CharOccurence cl = iter.next();
                if (prev != null && iter.hasNext()) {
                    cl.count -= 2*mn;
                } else {
                    cl.count -= mn;
                }

                if (cl.count <= 0) {
                    iter.remove();
                    flag = false;
                } else {
                    if (prev != null) {
                        if (prev.c == cl.c) {
                            prev.count += cl.count;
                            iter.remove();
                            flag = false;
                        }
                    }
                }
                if (flag || prev == null) {
                    prev = cl;
                }
            }
            mn = Integer.MAX_VALUE;
            for (CharOccurence co : s) {
                if (mn > co.count) {
                    mn = co.count;
                }
            }
            mn = (int) Math.ceil(mn/2.0);

        }
        System.out.println(res);
    }



}
class CharOccurence {
    int c;
    int count;
    CharOccurence(int c, int count) {
        this.c = c;
        this.count = count;
    }
}