import java.util.ArrayList;
import java.util.Scanner;

 

public class colouring_points {

 static class pair<T1, T2> {

	T1 first;
	T2 second;
	
	pair(T1 first,T2 second){
		
		this.first = first;
		this.second = second ;
	}
}
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		String str  = s.next();

		ArrayList<pair<Character,Integer>> arr = new ArrayList<>();

		int count=0;
		char c = str.charAt(0);

		for(int i=0;i<str.length();i++){
			if(str.charAt(i)==c){
				count++;
			}else{
				arr.add(new pair(c,count));
				count=1;
				c=str.charAt(i);
			}
		}

		arr.add(new pair(c,count));
		int size=arr.size();
		int ans=0;



		while(size>1){

			ans++;
			ArrayList<pair<Character,Integer>> arr1 = new ArrayList<>();
			for(int i=0;i<size;i++){
				if(i==0 || i==size-1){
					int temp = arr.get(i).second;
					temp-=1;
					if(temp>0){
						arr1.add(new pair(arr.get(i).first,temp));
					}
				}else{
					int temp = arr.get(i).second;
					temp-=2;
					if(temp>0){
						arr1.add(new pair(arr.get(i).first,temp));
					}
				}
			}


if(arr1.size()<=1){
break;
}
			ArrayList<pair<Character,Integer>> arr2 = new ArrayList<>();
			char c1 =arr1.get(0).first;
			int count1 = arr1.get(0).second;

			for(int i=1;i<arr1.size();i++){
				if(arr1.get(i).first==c1){
					count1+=arr1.get(i).second;
				}else{
					arr2.add(new pair(c1,count1));
					c1=arr1.get(i).first;
					count1=arr1.get(i).second;
				}
			}
			arr2.add(new pair(c1,count1));

			arr = arr2;
			size=arr2.size();
		}
		
		System.out.println(ans);
	}

}