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

public class Test {
    int readInt() {
        int ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    final int N = 1000_010;
    int[][] nb = new int[N][2];
    boolean[] removed = new boolean[N], updated = new boolean[N];
    List<Integer> removes = new ArrayList<>(), updates = new ArrayList<>();
    TreeSet<Integer>[] sets = new TreeSet[128];
    char[] pts;
    int n;

    void add(int[] a, int i) {
        a[1] = a[0];
        a[0] = i;
    }
    void remove(int i) {
        if (!removed[i]) {
            removes.add(i);
            removed[i] = true;
        }
    }

    void update(int i) {
        if (!updated[i]) {
            updates.add(i);
            updated[i] = true;
        }
    }

    Scanner sca = new Scanner(System.in);
    void start() {
        for (int i = 'a'; i <= 'z'; i++) sets[i] = new TreeSet<>();
        pts = sca.nextLine().toCharArray();
        n = pts.length;
        for (int i = 0; i < n; i++) {
            sets[pts[i]].add(i);
            if (i < n - 1) {
                add(nb[i], i+1);
                add(nb[i+1], i);
                if (pts[i] != pts[i + 1]) {
                    remove(i);
                    remove(i + 1);
                }
            }
        }
        int ans = 0;
        while (!removes.isEmpty()) {
            ans++;
            updates.clear();
            for (int i : removes) {
                for (int j : nb[i]) {
                    if (j >= 0 && !removed[j]) update(j);
                }
                sets[pts[i]].remove(i);
            }
            for (int i : updates) {
                nb[i][0] = -1;
                int low = -1, high = n + 1;
                for (int j = 'a'; j <= 'z'; j++) {
                    Integer lower = sets[j].lower(i), higher = sets[j].higher(i);
                    if (lower != null) low = Math.max(low, lower);
                    if (higher != null) high = Math.min(high, higher);
                }
                if (low >= 0) add(nb[i], low);
                if (high <= n) add(nb[i], high);
            }
            removes.clear();
            loop:
            for (int i : updates) {
                for (int j : nb[i]) {
                    if (j >= 0 && pts[i] != pts[j]) {
                        remove(i);
                        continue loop;
                    }
                }
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {

        new Test().start();

    }
}