import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.TreeSet;


public final class CF_455_D2{

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}


	static long mod=1000000007;

	static int[] left,right;
	static char[] c;
	static int n;

	static int solveBof2(){
		int it=0;
		boolean goon=true;
		char[] d=c;
		//char[] d=new char[n];
		//System.arraycopy(c,0,d,0,n);

		int[] right=new int[n+1];
		int[] left=new int[n+1];
		for (int i=0;i<n+1;i++){
			right[i]=i+1;
			left[i]=i-1;
		}
		int[][] stack=new int[2][n+1];
		int[] st=new int[n+1];
		int e=0;
		int tot=0;
		for (int i=0;i<=n;i++)
			stack[e][st[e]++]=i;
		while (goon){
			int u=0;
			goon=false;
			tot+=st[e];
			e=1-e;
			st[e]=0;
			while (u<st[1-e]){
				int i=stack[1-e][u];
				if (i==0)
					i=right[i];
				int src=i;
				boolean manip=false;
				boolean destroy=false;
				if (i<=n && right[i]<=n && d[right[i]-1]!=d[i-1]) {
					destroy=true;
					manip=true;
				}
				while (destroy){
					while (i<=n && right[i]<=n && d[right[i]-1]!=d[i-1]){
						i=right[i];
					}
					destroy=false;
					if (i<=n){
						i=right[i];
						if (i<=n && right[i]<=n && d[right[i]-1]!=d[i-1])
							destroy=true;
					}
				}
				if (manip){
					if (src>0)
						d[src-1]='#';
					if (i-2>=0)
						d[i-2]='#';
					goon=true;
					//log("adding:"+last);
					int k=left[src];
					if (k>0 && d[k-1]!='#') {
						stack[e][st[e]++]=k;
					}

				} 

				if (i<=n)
					left[i]=left[src];
				if (left[src]>=0)
					right[left[src]]=i;
				if (i<n)
					i=right[i];
				else
					i=n+1;


				while (u<st[1-e] && stack[1-e][u]<i)
					u++;

			}
			if (goon)
				it++;

		}
		log("proc:"+tot+" vs "+n);
		return it;
	}



	// Global vars
	static BufferedWriter out;
	static InputReader reader;



	
	static void process() throws Exception {


		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader=new InputReader(System.in);

		String s=reader.readString();

		c=s.toCharArray();
		n=c.length;

		output(solveBof2());
		try {
			out.close();
		}
		catch (Exception EX){}


	}


	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}


		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}




		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}


}