import java.io.*;
import java.util.*;
public class FF {
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		char [] s=sc.next().toCharArray();
		int n=s.length;
		ArrayList<pair> arr=new ArrayList<pair>();
		for(int i=0;i<n;i++){
			int j=i;
			while(j+1<n && s[j+1]==s[i])
				j++;
			arr.add(new pair(s[i], j-i+1));
			i=j;
		}
		int c=0;
		while(true){
			if(arr.size()<=1)
				break;
			c++;
			for(int i=0;i<arr.size();i++){				
				if(i==0 || i==arr.size()-1)
					arr.get(i).x--;
				else
					arr.get(i).x-=2;
				if(arr.get(i).x<0)
					arr.get(i).x=0;
			}
			ArrayList<pair> tmp=new ArrayList<pair>();
			for(int i=0;i<arr.size();i++){
				if(arr.get(i).x==0)
					continue;
				int sum=arr.get(i).x;
				int j=i;
				while(j+1<arr.size() && (arr.get(j+1).x==0 || arr.get(j+1).c==arr.get(i).c)){
					j++;
					sum+=arr.get(j).x;
				}
				tmp.add(new pair(arr.get(i).c, sum));
				i=j;
			}
			
			arr=tmp;
		}
		pw.println(c);
		pw.flush();
		pw.close();
	}
	
	static class pair{
		char c;
		int x;
		pair(char c,int x){
			this.c=c;
			this.x=x;
		}
		public String toString(){
			return c+" "+x;
		}
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.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());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}