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

public class ProblemD {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String in = input.next();
		ArrayList<Integer> size = new ArrayList<Integer>();
		ArrayList<Character> value = new ArrayList<Character>();

		{
			char cur = in.charAt(0);
			int sz = 1;
			for (int idx = 1; idx < in.length(); idx++) {
				if (in.charAt(idx) == cur) {
					sz++;
				} else {
					size.add(sz);
					value.add(cur);
					cur = in.charAt(idx);
					sz = 1;
				}
			}
			size.add(sz);
			value.add(cur);
		}

		int count = 0;
		while (value.size() > 1) {
			int minDecrease = Integer.MAX_VALUE;
			for (Integer i : size) {
				minDecrease = Math.max(1, Math.min(minDecrease, i / 2));
			}
			count += minDecrease;
//			System.err.println(size + " " + value);
			// decrease size
			for (int i = 0; i < size.size(); i++) {
				if (i == 0 || i == size.size() - 1) {
					size.set(i, size.get(i) - minDecrease);
				} else {
					size.set(i, Math.max(0, size.get(i) - 2 * minDecrease));
				}
			}
//			System.err.println(size + " " + value);
			// remove those which go to zero
			{
				ArrayList<Character> newValue = new ArrayList<Character>();
				ArrayList<Integer> newSize = new ArrayList<Integer>();
				for (int i = 0; i < size.size(); i++) {
					if (size.get(i) != 0) {
						newSize.add(size.get(i));
						newValue.add(value.get(i));
					}
				}
				size = newSize;
				value = newValue;
			}
//			System.err.println(size + " " + value);
			// merge same characters
			if(size.size() != 0){
				ArrayList<Character> newValue = new ArrayList<Character>();
				ArrayList<Integer> newSize = new ArrayList<Integer>();
				char cur = value.get(0);
				int total = size.get(0);
				for (int i = 1; i < size.size(); i++) {
					if (value.get(i) == cur) {
						total += size.get(i);
					} else {
						newValue.add(cur);
						newSize.add(total);
						cur = value.get(i);
						total = size.get(i);
					}
				}
				newValue.add(cur);
				newSize.add(total);

				value = newValue;
				size = newSize;
			}
//			System.err.println("NEXT");
		}
		System.out.println(count);
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(Reader in) {
			br = new BufferedReader(in);
		}

		public FastScanner() {
			this(new InputStreamReader(System.in));
		}

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

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String readNextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readIntArray(int n) {
			int[] a = new int[n];
			for (int idx = 0; idx < n; idx++) {
				a[idx] = nextInt();
			}
			return a;
		}

		long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int idx = 0; idx < n; idx++) {
				a[idx] = nextLong();
			}
			return a;
		}
	}
}
