import java.util.*;
import java.io.*;
import java.math.*;
public class A{

    void solve(){
        char s[]=ns().toCharArray();
        int ans=0;
        int n=s.length;
        int left[]=new int[n];
        int right[]=new int[n];

        for(int i=0;i<n;i++){
            left[i]=i-1;
            right[i]=i+1;
        }
        Queue<Integer> q1=new LinkedList<>();
        Queue<Integer> q2=new LinkedList<>();
        for(int i=0;i<n;i++){
            if((i-1>=0 && s[i-1]!=s[i]) || (i+1<n && s[i+1]!=s[i])) {
                q1.offer(i);

            }
        }
        boolean removed[]=new boolean[n+1];
        Stack<Integer> stk=new Stack<>();
        int left2[]=new int[n+1];


        while(true){
            q2.clear();
            if(q1.isEmpty()) break;
            int prev=-1;
            for(int t : q1) left2[t]=left[t];
            for(int t  :q1) {

                if(right[t]>=0 && right[t]<n) left[right[t]]=left[t];
                stk.push(t);


            }
            while(!stk.isEmpty()){
                int t=stk.pop();
                if(left2[t]>=0 && left2[t]<n) right[left2[t]]=right[t];
            }
            for(int t : q1){

            }
//            for(int i=0;i<n;i++) pw.print(left[i]+" ");
//            pw.println("");
//            for(int i=0;i<n;i++) pw.print(right[i]+" ");
            while(!q1.isEmpty()){
                int t=q1.poll();
                if(removed[t]) continue;
                removed[t]=true;
             //   pw.print(t+" ");

                int t1=left[t],t2=right[t];
                if(t1>=0 && t1<n){
                    if((left[t1]>=0 && left[t1]<n && s[left[t1]]!=s[t1]) || (right[t1]>=0 && right[t1]<n && s[right[t1]]!=s[t1]) && !removed[t1]) {
                        q2.offer(t1);

                    }
                }
                if(t2>=0 && t2<n){
                    if((left[t2]>=0 && left[t2]<n && s[left[t2]]!=s[t2]) || (right[t2]>=0 && right[t2]<n && s[right[t2]]!=s[t2]) && !removed[t2]) {
                        q2.offer(t2);

                    }
                }

            }

         //  pw.println("");
            q1.addAll(q2);
            ans++;

        }
        pw.println(ans);

    }


    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

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

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}