import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ColorfulPoints
{
    public static void main(String[] args)
    {
        new ColorfulPoints(System.in, System.out);
    }

    private static class Solver implements Runnable
    {
        int n;
        char[] s;
        BufferedReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            s = in.readLine().toCharArray();
            n = s.length;

            char ch = s[0];
            int ptr = 0;
            List<Group> groups = new ArrayList<>();

            while (ptr < n)
            {
                int size = 0;

                while (ptr < n && s[ptr] == ch)
                {
                    ptr++;
                    size++;
                }

                groups.add(new Group(ch, size));

                if (ptr < n)
                    ch = s[ptr];
            }

            int ans = 0;

            while (true)
            {
//                System.out.println("Groups : " + groups);

                int size = groups.size();
                int min = Math.min(groups.get(0).size, groups.get(size - 1).size);

                for (int i = 1; i < size - 1; i++)
                    min = Math.min(min, (int) Math.ceil(groups.get(i).size / 2.0));

                List<Group> temp = new ArrayList<>();

                for (int i = 0; i < size; i++)
                {
                    int steps = (i == 0 || i == size - 1 ? groups.get(i).size : (int) Math.ceil(groups.get(i).size /
                            2.0));

                    if (steps > min)
                    {
                        groups.get(i).size -= min;

                        if (i > 0 && i < size - 1)
                            groups.get(i).size -= min;

                        int cnt = temp.size();

                        if (cnt > 0 && temp.get(cnt - 1).ch == groups.get(i).ch)
                            temp.get(cnt - 1).size += groups.get(i).size;
                        else
                            temp.add(groups.get(i));
                    }
                }

                groups = temp;
                ans += min;

                if (groups.size() < 2)
                    break;
            }

            out.println(ans);
        }

        class Group
        {
            char ch;
            int size;

            Group(char ch, int size)
            {
                this.ch = ch;
                this.size = size;
            }

            @Override
            public String toString()
            {
                return String.format("{%c=>%d}", ch, size);
            }

        }

        public Solver(BufferedReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

        @Override
        public void run()
        {
            try
            {
                solve();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    private ColorfulPoints(InputStream inputStream, OutputStream outputStream)
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        PrintWriter out = new PrintWriter(outputStream);
        Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 29);

        try
        {
            thread.start();
            thread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        try
        {
            in.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        out.flush();
        out.close();
    }

}
