import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	final static long mod = 1000000007;
	
	public static void main(String[] args) throws Exception {

		STDIN scan = new STDIN();
		PrintWriter pw = new PrintWriter(System.out);
	
		String s = scan.nextLine();
		ArrayList<Node> a = new ArrayList<>();
		for(int i = 0; i < s.length(); i++) {
			int count = 1;
			while(i+1 < s.length() && s.charAt(i+1) == s.charAt(i)) {
				count++; i++;
			}
			a.add(new Node(s.charAt(i), count));
		}
		
		int ans = 0;
		while(a.size() > 1) {
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < a.size(); i++) {
				if(i == 0 || i == a.size()-1) min = Math.min(min, a.get(i).val);
				else min = Math.min(min, (a.get(i).val + 1) / 2);
			}
			ArrayList<Node> b = new ArrayList<>();
			for(int i = 0; i < a.size(); i++) {
				if(i == 0 || i == a.size()-1) a.get(i).val -= min;
				else a.get(i).val -= 2 * min;
				if(a.get(i).val <= 0) continue;
				if(b.size() > 0 && b.get(b.size()-1).c == a.get(i).c) b.get(b.size()-1).val += a.get(i).val;
				else b.add(a.get(i));
			}
			a = b;
			ans += min;
		}
		pw.println(ans);
		
		pw.flush();
	}

	static class Node{
		char c;
		int val;
		public Node(char a, int b) {
			c = a;
			val = b;
		}
	}
	
	
	static class STDIN {
		BufferedReader br;
		StringTokenizer st;

		public STDIN() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

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

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

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

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws Exception {
			return br.readLine();
		}
	}
}