def unbalance(S):
    max_sum0 = 0
    now_sum0 = 0
    max_sum1 = 0
    now_sum1 = 0
    for i in range(len(S)):
        if S[i] == "0":
            now_sum0 += 1
            now_sum1 = max(now_sum1 - 1, 0)
        else:
            now_sum0 = max(now_sum0 - 1, 0)
            now_sum1 += 1
        max_sum0 = max(max_sum0, now_sum0)
        max_sum1 = max(max_sum1, now_sum1)
    return max(max_sum0, max_sum1)

def solve(S):
    st = "" # debug
    if S[0] == "?":
        for i in range(len(S)):
            if S[i] == "0":
                if i % 2 == 0:
                    S[0] = "0"
                else:
                    S[0] = "1"
                break
            elif S[i] == "1":
                if i % 2 == 0:
                    S[0] = "1"
                else:
                    S[0] = "0"
                break
    if S[0] == "?":
        return 1

    now_sum0 = 0
    now_sum1 = 0
    un = 1
    val = -1
    for i in range(len(S)):
        if S[i] == "0":
            now_sum0 += 1
            now_sum1 = max(now_sum1 - 1, 0)
            val = -1
            st += "0" # debug
        elif S[i] == "1":
            now_sum0 = max(now_sum0 - 1, 0)
            now_sum1 += 1
            val = -1
            st += "1" # debug
        else :
            if now_sum0 > now_sum1:
                if now_sum0 > now_sum1 + 1:
                    now_sum1 += 1
                    now_sum0 = max(now_sum0 - 1, 0)
                    st += "1" # debug
                elif i + 1 < len(S):
                    if S[i+1] == "0":
                        now_sum0 = max(now_sum0 - 1, 0)
                        now_sum1 += 1
                        st += "1" # debug
                    elif S[i+1] == "1":
                        now_sum0 += 1
                        now_sum1 = max(now_sum1 - 1, 0)
                        st += "0" # debug
                    else:
                        now_sum1 += 1
                        now_sum0 = max(now_sum0 - 1, 0)
                        st += "1" # debug
            elif now_sum1 > now_sum0:
                if now_sum1 > now_sum0 + 1:
                    now_sum0 += 1
                    now_sum1 = max(now_sum1 - 1, 0)
                    st += "0" # debug
                elif i + 1 < len(S):
                    if S[i+1] == "0":
                        now_sum0 = max(now_sum0 - 1, 0)
                        now_sum1 += 1
                        st += "1" # debug
                    elif S[i+1] == "1":
                        now_sum0 += 1
                        now_sum1 = max(now_sum1 - 1, 0)
                        st += "0" # debug
                    else:
                        now_sum0 += 1
                        now_sum1 = max(now_sum1 - 1, 0)
                        st += "0" # debug
            else:
                if i + 1 < len(S):
                    if S[i+1] == "0":
                        now_sum0 = max(now_sum0 - 1, 0)
                        now_sum1 += 1
                        st += "1" # debug
                    elif S[i+1] == "1":
                        now_sum0 += 1
                        now_sum1 = max(now_sum1 - 1, 0)
                        st += "0" # debug
                    else:                   
                        if val == -1:
                            for j in range(i, len(S)):
                                if S[j] == "0":
                                    if (j - i) % 2 == 0:
                                        val = 0
                                    else:
                                        val = 1
                                    break
                                elif S[j] == "1":
                                    if (j - i) % 2 == 0:
                                        val = 1
                                    else:
                                        val = 0
                                    break
                        if val == 1:
                            now_sum0 = max(now_sum0 - 1, 0)
                            now_sum1 += 1
                            st += "1" # debug
                        elif val == 0:
                            now_sum0 += 1
                            now_sum1 = max(now_sum1 - 1, 0)
                            st += "0" # debug
                        else:
                            return unbalance(st)
                else:
                    return unbalance(st)
    return unbalance(st)

S = list(input())
print(min(solve(S), solve(S[::-1])))

