/*
Keep solving problems.
*/

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

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {0, -1, 0, 1};
    int[] dy = {1, 0, -1, 0};

    class Pair implements Comparable<Pair> {
        int x;
        int y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if(x != o.x) {
                return Integer.compare(x, o.x);
            }
            else {
                return Integer.compare(y, o.y);
            }
        }

        @Override
        public int hashCode() {
            int res = 13;
            res = 37 * res + x;
            res = 37 * res + y;
            return res;
        }

        @Override
        public boolean equals(Object obj) {
            if(obj == null) {
                return false;
            }
            if(!(obj instanceof Pair)) {
                return false;
            }
            Pair o = (Pair) obj;
            return this.x == o.x && this.y == o.y;
        }

        @Override
        public String toString() {
            return "x: " + x + ", y: " + y;
        }
    }

    void solve() throws IOException {
        char[] arr = nextString().toCharArray();
        List<Pair> ls = new ArrayList<>();
        int start = 0;
        int n = arr.length;
        while (start < n) {
            int cnt = 0;
            int end = start;
            while (end < n && arr[end] == arr[start]) {
                cnt++;
                end++;
            }
            ls.add(new Pair(arr[start], cnt));
            start = end;
        }
        
        int res = 0;
        while (ls.size() > 1) {
            for (int i = 0; i < ls.size(); i++) {
                if (i == 0 || i == ls.size() - 1) {
                    ls.get(i).y--;
                }
                else {
                    ls.get(i).y -= 2;
                }
                ls.get(i).y = Math.max(0, ls.get(i).y);
            }
            List<Pair> tmp = new ArrayList<>();
            for (Pair p : ls) {
                if (p.y == 0) {
                    continue;
                }

                if (!tmp.isEmpty() && tmp.get(tmp.size() - 1).x == p.x) {
                    tmp.get(tmp.size() - 1).y += p.y;
                }
                else {
                    tmp.add(p);
                }
            }

            ls = tmp;
            res++;
        }

        out(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }

    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

