import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class D {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static int[]t;
	static int n;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		char[]a = next().toCharArray();
		n = a.length;
		int ans = 0;
		int[]left = new int[n], right = new int[n];
		int cnt = 0;
		int begin = 0;
		t = new int[n+1];
		for (int i = 1; i <= n; i++) {
			if (i==n || a[i] != a[i-1]) {
				left[cnt] = begin;
				right[cnt] = i-1;
				cnt++;
				begin = i;
			}
			inc(i, 1);
		}
		while (true) {
			boolean[]used = new boolean[26];
			for (int i = 0; i < cnt; i++) {
				used[a[left[i]]-'a'] = true;
			}
			int diff = 0;
			for (int i = 0; i < 26; i++) {
				if (used[i])
					diff++;
			}
			if (diff <= 1)
				break;
			ans++;
			inc(right[0]+1, -1);
			right[0]--;
			if (cnt > 1) {
				inc(left[cnt-1]+1, -1);
				left[cnt-1]++;
			}
			for (int i = 1; i < cnt-1; i++) {
				inc(left[i]+1, -1);
				left[i]++;
				inc(right[i]+1, -1);
				right[i]--;
			}
			int[]newL = new int[cnt];
			int[]newR = new int[cnt];
			int newCnt = 0;
			for (int i = 0; i < cnt; i++) {
				if (sum(left[i], right[i]) > 0) {
					if (newCnt > 0 && a[left[i]]==a[newL[newCnt-1]]) {
						newR[newCnt-1] = right[i];
						continue;
					}
					newL[newCnt] = left[i];
					newR[newCnt] = right[i];
					newCnt++;
				}
			}
			cnt = newCnt;
			for (int i = 0; i < cnt; i++) {
				left[i] = newL[i];
				right[i] = newR[i];
			}
		}
		System.out.println(ans);
		pw.close();
	}
	private static int sum(int left, int right) {
		left++;
		right++;
		return sum(right)-sum(left-1);
	}
	private static int sum(int ind) {
		int res = 0;
		for (int i = ind; i >= 1; i = (i & (i-1))) {
			res += t[i];
		}
		return res;
	}
	private static void inc(int ind, int delta) {
		for (int i = ind; i <= n; i = (i | (i-1))+1) {
			t[i] += delta;
		}
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}