import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DColorfulPoints solver = new DColorfulPoints();
        solver.solve(1, in, out);
        out.close();
    }

    static class DColorfulPoints {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            char[] arr = sc.nextLine().toCharArray();
            int n = arr.length;
            int ans = 0;
            TreeSet<Character> ts = new TreeSet<>();
            ArrayList<Character> a = new ArrayList<>();
            boolean f = false;
            while (true) {
                if (f && ts.size() <= 1) break;
                f = true;
                a = new ArrayList<>();
                for (int i = 0; i < n; i++) {
                    if (i == 0 && i + 1 < n && arr[i] == arr[i + 1]) {
                        a.add(arr[i]);
                    } else if (i == n - 2 && arr[i] == arr[i + 1]) {
                        a.add(arr[i]);
                    } else if (i - 1 >= 0 && i + 1 < n && arr[i] == arr[i - 1] && arr[i] == arr[i + 1]) {
                        a.add(arr[i]);
                    }
                }
                ts = new TreeSet<>();
                arr = new char[a.size()];
                int j = 0;
                for (Character x : a) {
                    ts.add(x);
                    arr[j] = x;
                    j++;
                }
                ans++;
                n = arr.length;
            }
            pw.println(ans);
        }

    }

    static class Scanner {
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

        public String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

    }
}

