import java.io.*;
import java.util.*;
public class h {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
        static class TaskE {
        class pair{
        	int n,v;pair(int a,int b){n=a;v=b;}
        	public String toString() {return n+"-"+v;}
        }
         public void solve(int testNumber, InputReader in, PrintWriter out) {
           String s=in.next().trim();
           ArrayList<pair> al[]=new ArrayList[500011];
           int p=s.charAt(0);int c=1;al[0]=new ArrayList<>();int t=0;
           for(int i=1;i<s.length();i++) {
        	   int ch=s.charAt(i);
        	   if(ch==p)++c;else {
        		   al[0].add(new pair(p,c));c=1;p=ch;
        	   }
           }al[0].add(new pair(p,c));int ans=0;
           while(al[t].size()>1) {
        	   boolean k=false;int pv=al[t].get(0).n;
        	    for(int i=1;i<al[t].size();i++) {
        	    	if(al[t].get(i).n!=pv) {k=true;break;}
        	    }
        	    if(k)++ans;else break;  
        	   //System.out.println(al[t]);
        	   al[t+1]=new ArrayList<>();
        	   for(int i=0;i<al[t].size()-1;i++) {
        		   int n1=al[t].get(i).n,n2=al[t].get(i+1).n;
        		   int v1=al[t].get(i).v,v2=al[t].get(i+1).v;
        		   if(n1==n2) {
        			   al[t].set(i+1,new pair(n1,v1+v2));
        		   }else {
        			   if(v1-1>0)al[t+1].add(new pair(n1,v1-1));
        			   al[t].set(i+1,new pair(n2,v2-1));
        		   }
        	   }
        	   int sz=al[t].size();pair P=al[t].get(sz-1);
        	   if(P.v>0)al[t+1].add(new pair(P.n,P.v));
        	   //System.out.println(al[t+1]);
        	   ++t;
           }out.print(ans);
       }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}