def solve(S):
    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

    sum0 = 0
    sum1 = 0
    un = 1
    val = -1
    for i in range(len(S)):
        if S[i] == "0":
            sum0 += 1
            val = -1
        elif S[i] == "1":
            sum1 += 1
            val = -1
        else :
            if sum0 > sum1:
                sum1 += 1
            elif sum1 > sum0:
                sum0 += 1
            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:
                    sum1 += 1
                elif val == 0:
                    sum0 += 1
                else:
                    return un
        un = max(un, abs(sum0 - sum1))
    return un

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

