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


public class Main {
    private static char [] S ;
    private static boolean [] dead;
    private static int n;
    private static int [] L;
    private static int [] prv,nxt;
    private static ArrayList<Integer> [] AS = new ArrayList[2];


    private static void cover(int i) {
        int l = prv[i],r = nxt[i];
        nxt[l] = r;
        prv[r] = l;
        dead[i] = true;
    }

    private static void insert(int l,int r,int cur) {
        if (l > r) return;
        if(!AS[cur].isEmpty()) {
            int or = AS[cur].get(AS[cur].size()-1);
            if (S[or-1] == S[l-1]) {
                AS[cur].set(AS[cur].size()-1,r);
                L[r] = L[or];
            }
            else {
                L[r] = l;
                AS[cur].add(r);
            }
        }
        else{
            L[r] = l;
            AS[cur].add(r);
        }
    }
    public static void main(String[] args) throws Exception{
        IO io = new IO(null,null);
        S = io.getNext().toCharArray();
        n = S.length;
        dead = new boolean[n+2];
        L = new int[n+2];
        prv = new int[n+2];
        nxt = new int[n+2];

        int ans = 0;
        for (int i = 1;i < n;i++)
            if (S[i-1] != S[i]) {
                dead[i] = dead[i + 1] = true;
                ans = 1;
            }
        for (int i = 0;i < 2;i++) AS[i] = new ArrayList<>();

        for (int i = 0;i <= n+1;i++) {
            prv[i] = i-1;
            nxt[i] = i+1;
        }
        for (int i = 1;i <= n;i++)
            if (dead[i])
                cover(i);
        for (int i = 1;i <= n;i++) if(!dead[i]) {
            int j = i;
            while (j <= n && !dead[j]) j++;
            insert(i,j-1,0);
            i = j-1;
        }


        int cur = 0,lst = 1;

        while (AS[cur].size() > 1) {
            cur ^= 1;
            lst ^= 1;
            AS[cur].clear();

            for(int i = 0;i < AS[lst].size();i++) {
                int r = AS[lst].get(i),nl = L[r],nr = r;
                if(i != 0) {
                    cover(L[r]);
                    nl = nxt[nl];
                }
                if(i != AS[lst].size()-1) {
                    cover(r);
                    nr = prv[r];
                }
                insert(nl,nr,cur);
            }
            ans++;
        }
        io.println(ans);
        io.close();
    }
}



class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

    public boolean hasMore() throws IOException{
        if(st != null && st.hasMoreTokens()) return true;
        if(br != null && br.ready()) return true;
        return false;
    }
    public String getNext() throws FileNotFoundException, IOException{
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
    public void outputArr(Object [] A) throws IOException{
        int L = A.length;
        for (int i = 0;i < L;i++) {
            if(i > 0) writer.print(" ");
            writer.print(A[i]);
        }
        writer.print("\n");
    }
}

