import java.lang.*;
import java.io.*;
import java.util.*;

public class Main {

    class Pair implements Comparable<Pair>{
        int l, r;

        Pair(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public int compareTo(Pair o) {
            return Integer.compare(l, o.l);
        }
    }

    public void solve() throws IOException {
        char s[] = nextToken().toCharArray();
        int n = s.length;
        int lvl[] = new int[n];
        TreeSet<Pair> q = new TreeSet<>();
        int b = 0, e = 0;
        for (int i = 1; i < n; i++) {
            if (s[i] == s[i - 1]) {
                if (b == 0 && e == 0) {
                } else {
                    q.add(new Pair(b, e));
                }
                b = i;
            } else {
                lvl[i - 1] = 1;
                lvl[i] = 1;
                e = i;
            }
        }
        if(q.size() == 0) {
            out.print(0);
            return;
        }
        int type = 2;
        Pair last = null;
        while (true) {
            for(Pair p : q){
                if(last != null && last.r == p.l - 1 ){
                    int l = last.l;
                    int r = p.r;
                    q.remove(last);
                    q.remove(p);
                    last = new Pair(l, r);
                    q.add(last);
                }
            }
            int cnt = 0;
            for(Pair p : q){
                if(p.l > 1 && p.r < n - 1){
                    if(s[p.l - 1] != s[p.r + 1]){
                        lvl[p.l - 1] = type;
                        lvl[p.r + 1] = type;
                        int l = p.l - 1;
                        int r = p.r + 1;
                        q.remove(p);
                        q.add(new Pair(l, r));
                        cnt++;
                    }
                }
            }
            if(cnt == 0) break;
            type++;
        }
        out.print(type - 1);
    }

    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("pnumbers.in"));
//            out = new PrintWriter(new File("out.txt"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

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

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

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

}