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_D{

	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[] next(int i){
		if (right[i]==n)
			return new int[]{-1,n};
		if (c[i]==c[right[i]])
			return new int[]{0,right[i]};
		boolean destroy=true;

		while (destroy && i<n && right[i]<n){
			if (c[i]!=c[right[i]])
				i=right[i];
			else {
				destroy=false;
				i=right[i];
				if (i<n && right[i]<n && c[right[i]]!=c[i]){
					destroy=true;
					i=right[i];
				}
			}
			// start again
		}
		return new int[]{1,i};
	}

	static int solveKO(){


		int[][] stack=new int[2][n];
		int[] ref=new int[n];
		for (int i=0;i<n;i++)
			ref[i]=i;
		int[] st=new int[2];
		// first pass
		int i=0;

		int last=-1;
		// first pass
		boolean goon=false;
		int it=0;
		int e=0;
		st[e]=0;
		while (i<n && right[i]<n){

			int[] tmp=next(i);
			if (tmp[0]>0){
				if (!goon) {
					goon=true;
					it++;
				}
				if (last>=0)
					stack[e][st[e]++]=last;
			}
			left[i]=last;

			if (last>=0)
				right[last]=tmp[1];
			last=i;
			i=tmp[1];
		}
		log(goon+" "+it);
		log(stack[e],st[e]);
		log(right);
		// now explore
		while (goon){
			log("pass");
			e=1-e;
			goon=false;
			st[e]=0;
			int u=0;
			last=-1;
			while (u<st[1-e]){
				i=stack[1-e][st[1-e]];
				if (i<n && right[i]<n){
					log("i:"+i+" "+right[i]);

					int[] tmp=next(i);
					if (tmp[0]>0){
						if (!goon) {
							goon=true;
							it++;
						}
						if (last>=0)
							stack[e][st[e]++]=last;
					}
					left[i]=last;
					if (last>=0)
						right[last]=tmp[1];
					last=i;
					i=tmp[1];
					while (u<st[1-e] && stack[1-e][u]<i)
						u++;
				} else 
					break;
			}

		}
		return it;

	}


	static int solveBourrin(){

		char[] bob=new char[n];
		System.arraycopy(c,0,bob,0,n);
		int it=0;
		boolean goon=true;
		
		while (goon){
			goon=false;
			int i=0;
			while (i<n){
				int src=i;
				while (i<n && right[i]<n && bob[right[i]]!=bob[i]){
					i=right[i];
				}
				if (right[src]!=n && i!=src){
					goon=true;
				}
				if (i<n)
					right[src]=right[i];
				else
					right[src]=n;
				i=right[src];
			}
			if (goon)
				it++;
			log(new String(bob));
		}
		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;
		s+="#";
		left=new int[n];
		right=new int[n];
		for (int i=0;i<n;i++){
			left[i]=i-1;
			right[i]=i+1;

		}

		output(solveBourrin());
		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;
		}
	}


}