import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;


/*

 */
public class D455 {
	
	public static void main(String[] args) {
		FS scan = new FS(System.in);
		String S = scan.next();
		
		char x = S.charAt(0);
		int count = 1;
		ArrayList<Seg> list = new ArrayList<>();
		for(int i=1;i<S.length();i++) {
			char t = S.charAt(i);
			if(t==x) {
				count++;
			}
			if (t!=x){
				list.add(new Seg(count, x));
				count = 1;
				x = t;
			}
		}
		list.add(new Seg(count,x));
		
		int sol = 0;
		while(list.size()>1) {
//			System.out.println(list);
			int min = 1000000000;
			for(int i=0;i<list.size();i++) {
				int steps;
				if(i==0||i==list.size()-1)steps = list.get(i).count;
				else steps = list.get(i).count+1 >> 1;
			
				min = Math.min(min, steps);
			}
			
//			System.out.println(min);
			
			ArrayList<Seg> next = new ArrayList<>();
			
			for(int i=0;i<list.size();i++) {
				int steps;
				if(i==0||i==list.size()-1)steps = list.get(i).count;
				else steps = list.get(i).count+1 >> 1;
				
				if(steps==min)continue;
				
				if(i==0||i==list.size()-1)list.get(i).count -= min;
				else list.get(i).count -= min*2;
				
				if(next.isEmpty())next.add(list.get(i));
				else {
					if(next.get(next.size()-1).color==list.get(i).color) 
						next.get(next.size()-1).count+=list.get(i).count;
					else
						next.add(list.get(i));
				}
			}
			sol += min;
			list = next;
		}
		
		System.out.println(sol);
		
		
	}
	private static class Seg {
		int count;
		char color;
		public Seg(int count, char color) {
			this.count=count;
			this.color = color;
		}
		public String toString() {
			return "("+count+","+color+")";
		}
	}
	
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() { return Double.parseDouble(next());}
	}
}
