import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

//http://codeforces.com/contest/909/problem/D
public class ColorfulPoints {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String points = s.nextLine();
		ArrayList<Character> p = new ArrayList<Character>(points.length());
		for (char c : points.toCharArray()) {
			p.add(c);
		}
		s.close();
		int operations = 0;
		TreeSet<Integer> toRemove = new TreeSet<Integer>();
		boolean removed = false;
		for (int i = 0; i < p.size() - 1; i++) {
			if (p.get(i) != p.get(i + 1)) {
				removed = true;
				while (i < p.size() - 1 && p.get(i) != p.get(i + 1)) {
					p.remove(i);
				}
				p.remove(i);
				if (i < p.size() && i > 0) {
					if (p.get(i - 1) != p.get(i)) {
						toRemove.add(i - 1);
					}
				}
			}
		}
		if (removed) {
			operations++;
		}
		while (toRemove.size() > 0) {
			removed = false;
			TreeSet<Integer> remCopy = toRemove;
			toRemove = new TreeSet<Integer>();
			int offSet = 0;
			for (int v : remCopy) {
				TreeSet<Integer> checked = new TreeSet<>();
				int i = v - offSet;
				if (checked.contains(i)) {
					continue;
				}
				checked.add(i);
				if (i >= 0 && i < p.size() - 1 && p.get(i) != p.get(i + 1)) {
					removed = true;
					while (i < p.size() - 1 && p.get(i) != p.get(i + 1)) {
						p.remove(i);
						offSet++;
					}
					p.remove(i);
					offSet++;
					if (i < p.size() && i > 0) {
						if (p.get(i - 1) != p.get(i)) {
							toRemove.add(i - 1);
						}
					}
				}
			}
			if (removed) {
				operations++;
			}
		}
		System.out.println(operations);

	}
}
