import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] a = in.readLine().toCharArray();
            int n = a.length;
            int ans = 0, t = 0;

            Stack<Character> stack = new Stack<>();
            for (int i = 0; i < n; i++) {

                if ((stack.size() > 0 && stack.peek() != a[i]) || (i < n - 1 && a[i] != a[i + 1])) {
                    stack.push(a[i]);
                } else {
                    char last = a[i];
                    int cnt = 0;
                    while (stack.size() > 0) {
                        char c = stack.pop();
                        if (!(c != last || (stack.size() > 0 && stack.peek() != c))) {
                            stack.push(c);
                            break;
                        } else cnt++;
                        last = c;
                    }
                    stack.push(a[i]);
                    if (cnt > 0) t++;
                    else {
                        ans = Math.max(t, ans);
                        t = 0;
                    }
                }

            }
            ans = Math.max(ans, t);
            if (stack.size() > 1 && stack.pop() != stack.pop()) ans++;
            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}

