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

public class ColorfulPoints {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		List<Integer> groups = new ArrayList<Integer>();
		List<Character> groupChars = new ArrayList<Character>();
		groups.add(0);
		groupChars.add(s.charAt(0));
		for(int i = 0; i < s.length(); ++i) {
			if(s.charAt(i) == groupChars.get(groupChars.size() - 1))
				groups.set(groups.size() - 1, groups.get(groups.size() - 1) + 1);
			else {
				groups.add(1);
				groupChars.add(s.charAt(i));
			}
		}
		int ops = 0;
//		System.out.println(groups);
//		System.out.println(groupChars);
		while(groups.size() > 1) {
			int minOps = Math.min(groups.get(0), groups.get(groups.size() - 1));
			for(int i = 1; i < groups.size() - 1; ++i)
				minOps = (int)Math.min(minOps, Math.ceil(groups.get(i) / 2.0));
			ops += minOps;
			List<Integer> newGroups = new ArrayList<Integer>();
			List<Character> newGroupChars = new ArrayList<Character>();
			for(int i = 0; i < groups.size(); ++i) {
				if(i == 0 || i == groups.size() - 1) {
					if(minOps < groups.get(i)) {
						if(newGroups.size() == 0 || groupChars.get(i) != newGroupChars.get(newGroupChars.size() - 1)) {
							newGroups.add(groups.get(i) - minOps);
							newGroupChars.add(groupChars.get(i));
						}
						else
							newGroups.set(newGroups.size() - 1, newGroups.get(newGroups.size() - 1) + groups.get(i) - minOps);
					}
				}
				else {
					if(minOps * 2 < groups.get(i)) {
						if(newGroups.size() == 0 || groupChars.get(i) != newGroupChars.get(newGroupChars.size() - 1)) {
							newGroups.add(groups.get(i) - minOps * 2);
							newGroupChars.add(groupChars.get(i));
						}
						else
							newGroups.set(newGroups.size() - 1, newGroups.get(newGroups.size() - 1) + groups.get(i) - minOps * 2);
					}
				}
			}
//			System.out.println("ops: " + minOps);
//			System.out.println(newGroups);
//			System.out.println(newGroupChars);
			groups = newGroups;
			groupChars = newGroupChars;
		}
		System.out.println(ops);
	}
}
