import java.awt.*;
import java.io.*;
import java.math.*;
import java.util.*;
 
 
public class TaskD {
	
	public static void main(String[] args) {
		new TaskD().run();
	}
	
	void solve(){
		TreeSet<Integer> st = new TreeSet<>();
		ArrayList<Integer> li = new ArrayList<>();
		char []a = in.next().toCharArray();
		for(int i = 0; i < a.length; i++){
			st.add(i);
			if(i > 0 && a[i] != a[i-1]) li.add(i);
			if(i+1 < a.length && a[i] != a[i+1])li.add(i);
		}
		int cnt = 0;
		while(li.size()>0){
			TreeSet<Integer> li2 = new TreeSet<>();
			for(int x: li) st.remove(x);
			for(int x: li){
				if(st.floor(x) != null){
					int p = st.floor(x);
					if(st.floor(p-1) != null && a[st.floor(p-1)] != a[p]){
						li2.add(p);
					}else if(st.ceiling(p+1) != null && a[st.floor(p+1)] != a[p]){
						li2.add(p);
					}
				}
				if(st.ceiling(x) != null){
					int p = st.ceiling(x);
					if(st.floor(p-1) != null && a[st.floor(p-1)] != a[p]){
						li2.add(p);
					}else if(st.ceiling(p+1) != null && a[st.floor(p+1)] != a[p]){
						li2.add(p);
					}
				}
			}
			li.clear();
			for(int x: li2)li.add(x);
			++cnt;
		}
		out.println(cnt);
	}

	FastScanner in;
	PrintWriter out;
	void run() {
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);
		int tests = 1;//in.nextInt();
		while(tests > 0){
			solve();
			tests--;
		}
		out.close();
	}
	
	class Pair implements Comparable<Pair>{
		Integer x, y;
		public Pair(int x, int y){
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			if(x.compareTo(o.x) == 0) return y.compareTo(o.y);
			return x.compareTo(o.x);
		}
		
	}
 
	class FastScanner {
		StringTokenizer st;
		BufferedReader bf;
 
		public FastScanner(InputStream is) {
			bf = new BufferedReader(new InputStreamReader(is));
		}
 
		public FastScanner(File f){
			try{
				bf = new BufferedReader(new FileReader(f));
			}
			catch(IOException ex){
				ex.printStackTrace();
			}
		}
		String next(){
			while(st == null || !st.hasMoreTokens()){
				try{
					st = new StringTokenizer(bf.readLine());
				}
				catch(Exception ex){
					ex.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		int[] readArray(int n){
			int[] a = new int[n];
			for(int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
	}
 
} 
