def main():
    s = input()
    #from random import choice
    #s = input()

    #n = 40
    #s = "".join([choice(["0", "1", "1", "?", "?"]) for _ in [0]*n])
    #print(s)
    m = 1
    t = [None]*m
    t[0] = 0
    for i in s:
        t2 = [[] for _ in [0]*m]
        for j in range(m):
            k = t[j]
            if k is None:
                continue
            if i != "1":
                t2[max(j-1, 0)].append(k-1)
            if i != "0":
                if j+1 < m:
                    t2[j+1].append(min(0, k+1))
                else:
                    t2.append([min(0, k+1)])
                    t.append(None)
                    m += 1
        for j in range(m):
            if t2[j]:
                t[j] = max(t2[j])
            else:
                t[j] = None
        for i in range(m-1, 1, -1):
            if t[i] == t[i-1]:
                t[i] = None
            if t[i] == t[i-2]:
                t[i] = None
        if m > 1:
            if t[1] == t[0]:
                t[1] = None
        for i in range(m-1, -1, -1):
            if t[i] is None:
                t.pop()
                m -= 1
            else:
                break
        if m > 3:
            if t[-3:] == [-1, None, 0]:
                m -= 2
                t.pop()
                t.pop()
        # print(t)
    ans = 10**10
    for i in range(m):
        if t[i] is not None:
            ans = min(ans, i-t[i])
    print(ans)


main()
