import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

public class D909 {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class G{
        char color;
        int count;
        public G(char a,int b){
            color = a;
            count = b;
        }
    }
    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            ArrayList<G> ar = new ArrayList<G>();
            ar.add(new G(s.charAt(0),1));
            for(int i = 1;i<s.length();i++){
                char c = s.charAt(i);        
                G tmp = ar.get(ar.size()-1);
                if(c == tmp.color){
                    tmp.count++;
                }else{
                    ar.add(new G(c,1));
                }
            }
            int ans = 0;
            while(ar.size() > 1){
                ans++;

                ar.get(0).count--;
                ar.get(ar.size()-1).count--;                
                for(int i=1;i<ar.size()-1;i++){
                    ar.get(i).count-=2;                                         
                }

                ArrayList<G> ar2 = new ArrayList<G>();
                int ptr = 0;
                for(int i=0;i<ar.size();i++){
                    if(ar.get(i).count>0){
                        ptr = i;
                        break;
                    }
                }
                ar2.add(ar.get(ptr));
                for(int i=ptr+1;i<ar.size();i++){
                    if(ar.get(i).count>0){                                       
                        if(ar.get(i).color == ar2.get(ar2.size()-1).color){
                            ar2.get(ar2.size()-1).count += ar.get(i).count;
                        }else{
                            ar2.add(ar.get(i));
                        }
                    }
                }
                ar = ar2;
                
            }
            out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public String nextLine() {
            String str = "";
            try
            {
                str = reader.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}