
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class D {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		ArrayList<Pair> arr = new ArrayList<>();
		int i = 0;
		while (i < s.length()) {
			char c = s.charAt(i);
			int st = i;
			while (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1))
				i++;
			arr.add(new Pair(i - st + 1, c));
			i++;
		}
		int ans = 0;
		while (arr.size() > 1) {
			ArrayList<Pair> tmp = new ArrayList<>();
			ans++;
			for (i = 0; i < arr.size(); i++) {
				if (i == 0 || i == arr.size() - 1)
					arr.get(i).size--;
				else
					arr.get(i).size -= 2;
			}
			for (i = 0; i < arr.size(); i++) {
				Pair cur = arr.get(i);
				if (cur.size <= 0)
					continue;
				if (tmp.isEmpty())
					tmp.add(new Pair(cur.size, cur.c));
				else {
					Pair last = tmp.get(tmp.size() - 1);
					if (last.c == cur.c)
						tmp.set(tmp.size() - 1, new Pair(last.size + cur.size, last.c));
					else
						tmp.add(cur);
				}
			}
			arr = tmp;
//			System.out.println(arr);
		}
		System.out.println(ans);
	}

	static class Pair {
		int size;
		char c;

		public Pair(int siz, char cc) {
			c = cc;
			size = siz;
		}

		public String toString() {
			return size + " " + c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

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

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

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

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}
