import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D909{

	void solve()
	{
		char[] s = ca2();
		ArrayDeque<Node> q = new ArrayDeque<>();
		int n = s.length;
		for(int i=1,sz=1,c=s[0];i<n;i++)
		{
			if(s[i] != c)
			{
				q.add(new Node(c, sz));
				sz = 1;
				c = s[i];
			}
			else
				sz++;
		}

		int ans = 0;
		while(q.size() > 1)
		{
			ArrayDeque<Node> t = new ArrayDeque<>();
			for(Node it : q)
			{
				if(it != q.peekFirst() && it != q.peekLast())
					it.size--;
				it.size--;
			}
			for(Node it : q)
			{
				if(it.size > 0)
				{
					if(t.peekLast() != null && t.peekLast().val == it.val)
						t.peekLast().size += it.size;
					else
						t.add(it);
				}
			}
			q = t;
			ans++;
		}
		
		out.println(ans);
	}
	
	class Node {
		
		int size, val;
		
		Node(int v, int s)
		{
			size = s;
			val = v;
		}
		
	}
	
	public static void main(String[] args){new D909().run();}
	
	private byte[] bufferArray = new byte[1024];
	private int bufLength = 0;
	private int bufCurrent = 0;
	InputStream inputStream;
	PrintWriter out;
	
	public void run()
	{
		inputStream = System.in;
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}
	
	int nextByte()
	{
		if(bufLength == -1)
			throw new InputMismatchException();
		if(bufCurrent >= bufLength)
		{
			bufCurrent = 0;
			try
			{bufLength = inputStream.read(bufferArray);}
			catch(IOException e)
			{ throw new InputMismatchException();}
			if(bufLength <= 0)
				return -1;
		}
		return bufferArray[bufCurrent++];
	}
	
	boolean isSpaceChar(int x)	{return (x < 33 || x > 126);}
	
	boolean isDigit(int x)	{return (x >= '0' && x <= '9');}
	
	int nextNonSpace()
	{
		int x;
		while((x=nextByte()) != -1 && isSpaceChar(x));
		return x;
	}
	
	int ni()
	{
		long ans = nl();
		if (ans >= Integer.MIN_VALUE && ans <= Integer.MAX_VALUE)
			return (int)ans;
		throw new InputMismatchException();
	}
	
	long nl()
	{
		long ans = 0;
		boolean neg = false;
		int x = nextNonSpace();
		if(x == '-') 
		{
			neg = true;
			x = nextByte();
		}
		while(!isSpaceChar(x))
		{
			if(isDigit(x))
			{
				ans = ans * 10 + x -'0';
				x = nextByte();
			}
			else
				throw new InputMismatchException();
		}
		return neg ? -ans : ans;
	}
	
	String ns2()
	{
		StringBuilder sb = new StringBuilder();
		int x = nextNonSpace();
		while(!isSpaceChar(x))
		{
			sb.append((char)x);
			x = nextByte();
		}
		sb.append(" ");
		return sb.toString();
	}
	
	char nc()	{ return (char)nextNonSpace();}
	
	char[] ca2()	{ return ns2().toCharArray();}
	
	int[] ia(int n)
	{
		int[] ans = new int[n];
		for(int i=0;i<n;i++)
			ans[i] = ni();
		return ans;
	}
	
	void db(Object... o) {System.out.println(Arrays.deepToString(o));}
	
}
