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

public class test {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		String str = s.nextLine();
		ArrayList<Integer> list = new ArrayList<Integer>();
		if (str.length() == 1) {
			System.out.println(1);
			s.close();
			return;
		}
		char curr = str.charAt(0);
		int count = 1;
		for (int i = 1; i < str.length(); i++) {
			if (str.charAt(i) == curr) {
				count++;
			} else {
				list.add(26 * count + Character.valueOf(curr) - Character.valueOf('a'));
				count = 1;
				curr = str.charAt(i);
			}
		}
		list.add(26 * count + Character.valueOf(curr) - Character.valueOf('a'));
	    for (int i = list.size() - 2; i >= 0; i--) {
				if (list.get(i) % 26 == list.get(i + 1) % 26) {
					list.set(i, list.get(i) + 26 * (list.get(i+1) / 26));
					list.remove(i+1);
				}
			}
		int numTimes = 0;
		while (list.size() > 1) {
			numTimes++;
			for (int i = list.size() - 1; i >= 0; i--) {
				if ((i == 0 || i == list.size() - 1) && list.get(i) < 52) {
					list.remove(i);
				} else if (!(i == 0 || i == list.size() - 1) && list.get(i) < 78) {
					list.remove(i);
				} else if (i == 0 || i == list.size() - 1) {
					list.set(i, list.get(i) - 26);
				} else {
					list.set(i, list.get(i) - 52);
				}
			}
			for (int i = list.size() - 2; i >= 0; i--) {
				if (list.get(i) % 26 == list.get(i + 1) % 26) {
					list.set(i, list.get(i) + 26 * (list.get(i+1) / 26));
					list.remove(i+1);
				}
			}
		}
		System.out.println(numTimes);
		s.close();
	}
}
