import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class ColorfulPoints {
    void solve() {
        char[] s = in.nextToken().toCharArray();
        int n = s.length;
        
        List<Segment> segments = new ArrayList<>();
        for (int l = 0; l < n; ) {
            int r = l;
            while (r < n && s[r] == s[l]) r++;
            segments.add(new Segment(s[l], r - l));
            l = r;
        }
        
        int ans = 0;
        while (segments.size() > 1) {
            int steps = Math.min(segments.get(0).size, segments.get(segments.size() - 1).size);
            for (int i = 1; i < segments.size() - 1; i++) steps = Math.min(steps, (segments.get(i).size + 1) / 2);
            List<Segment> next = new ArrayList<>();
            for (int i = 0; i < segments.size(); i++) {
                int delta = i == 0 || i == segments.size() - 1 ? steps : steps * 2;
                char color = segments.get(i).color;
                int size = segments.get(i).size - delta;
                if (size > 0) {
                    if (next.isEmpty() || next.get(next.size() - 1).color != color) next.add(new Segment(color, size));
                    else next.get(next.size() - 1).size += size;
                }
            }
            ans += steps;
            segments = next;
        }
        out.println(ans);
    }
    
    static class Segment {
        char color;
        int size;
        
        public Segment(char color, int size) {
            this.color = color;
            this.size = size;
        }
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new ColorfulPoints().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}
