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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		LinkedList<int[]> queue=new LinkedList<>();
		String str=in.next();
		int n=str.length();
		for(int i=0,j=0;j<n;) {
			char c=str.charAt(i);
			while(j<n&&str.charAt(j)==c) {
				j++;
			}
			queue.addLast(new int[] {c-'a',j-i});
			i=j;
		}
		int ret=0;
		while(queue.size()>1) {
			LinkedList<int[]> nqueue=new LinkedList<>();
			ret++;
			int size=queue.size();
			for(int i=0;i<size;i++) {
				int[] A=queue.pollFirst();
				if(i==0) {
					if(A[1]>1) {
						nqueue.add(new int[] {A[0],A[1]-1});
					}
				}else if(i==size-1) {
					if(A[1]>1) {
						if(nqueue.size()>0&&nqueue.peekLast()[0]==A[0]) {
							nqueue.peekLast()[1]+=A[1]-1;
						}else {
							nqueue.add(new int[] {A[0],A[1]-1});
						}
					}
				}else {
					if(A[1]>2) {
						if(nqueue.size()>0&&nqueue.peekLast()[0]==A[0]) {
							nqueue.peekLast()[1]+=A[1]-2;
						}else {
							nqueue.add(new int[] {A[0],A[1]-2});
						}
					}
				}
			}
			queue=nqueue;
		}
		out.println(ret);
	}
}



class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next() 
	{
		if(st==null || !st.hasMoreElements())
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt() 
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}