import java.io.*;
import java.util.*;

public class utkarsh{
	BufferedReader br;
	PrintWriter out;

	class pair{
		char C;
		int V;
		pair(char c, int v){
			C = c;
			V = v;
		}
	}

	ArrayList<pair> play(ArrayList<pair> a){
		ArrayList<pair> d = new ArrayList<>();
		for(pair p : a)	if(p.V > 0)	d.add(p);

		if(d.isEmpty())	return null;

		ArrayList<pair> t = new ArrayList<>();
		int j = d.get(0).V;
		int n = d.size();
		for(int i = 1; i < n; i++){
			if(d.get(i).C != d.get(i-1).C){
				t.add(new pair(d.get(i-1).C, j));
				j = 0;
			}
			j += d.get(i).V;
		}
		t.add(new pair(d.get(n-1).C, j));
		return t;
	}

	void solve(){
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		int i, j, n;
		String s = ns();
		n = s.length();
		ArrayList<pair> a = new ArrayList<>();

		j = 1;
		for(i = 1; i < n; i++){
			if(s.charAt(i) != s.charAt(i-1)){
				a.add(new pair(s.charAt(i-1), j));
				j = 0;
			}
			j++;
		}
		a.add(new pair(s.charAt(n-1), j));

		int ans = 0;
		while(a != null && a.size() > 1){
			ans++;
			n = a.size();
			for(i = 0; i < n; i++){
				if(i > 0 && i < (n-1))	a.get(i).V -= 2;
				else	a.get(i).V--;
			}
			a = play(a);
		}
		out.println(ans);
		
		out.flush();
	}

	int ni(){
		return Integer.parseInt(ns());
	}

	String ip[];
	int len, sz;

	String ns(){
		if(len >= sz){
			try{
				ip = br.readLine().split(" ");
				len = 0;
				sz = ip.length;
			}catch(IOException e){
				throw new InputMismatchException();
			}
			if(sz <= 0)	return "-1";
		}
		return ip[len++];
	}

	public static void main(String[] args){	new utkarsh().solve();	}
}