//package com.company;
//

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


public class Main {
    public static class Group{
        int val;
        int num;
        Group(int a){
            val = a;
            num = 0;
        }
    }

    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner(System.in);
        List<Group> mg = new ArrayList<>();
        String str = sc.next();
        int prevch = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c != prevch){
                Group g = new Group(c);
                g.num++;
                mg.add(g);
                prevch = c;
            } else {
                mg.get(mg.size() - 1).num++;
            }
        }
        boolean[] off = new boolean[mg.size()];
        int r = 0;
        while (true){
            int numon = 0;
            int min_del = Integer.MAX_VALUE;
            int stidx = 0;
            for (int i = 0; i < mg.size(); i++) {
                if (!off[i]) numon++;
                else continue;
                if (numon == 1) {
                    min_del = Math.min(min_del, mg.get(i).num);
                    stidx = i;
                }
                else if (i == mg.size() - 1) min_del = Math.min(min_del, mg.get(i).num);
                else min_del = Math.min(min_del, (mg.get(i).num + 1) / 2);
            }
            if (numon <= 1){
                break;
            }
            r+= min_del;
            for (int i = 0; i < mg.size(); i++) {
                if (off[i]) continue;
                if (i == stidx || i == mg.size() - 1){
                    mg.get(i).num -= min_del;
                } else {
                    mg.get(i).num -= min_del * 2;
                }
                if (mg.get(i).num <= 0){
                    off[i] = true;
                }
            }
            int prev_idx = -1;
            int prev_num = 0;
            int prev_char = 2;
            for (int i = 0; i < mg.size(); i++) {
                if (off[i]) continue;
                if (mg.get(i).val == prev_char){
                    mg.get(i).num += prev_num;
                    mg.get(prev_idx).num = 0;
                    off[prev_idx] = true;
                }
                prev_idx = i;
                prev_num = mg.get(i).num;
                prev_char = mg.get(i).val;
            }
        }
        System.out.println(r);
    }

    static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

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

        public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(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();}
    }
}