import itertools
import copy

syokiti = list(input())

last=[]
for i in itertools.product("10",repeat=syokiti.count("?")):
    yousuu=0
    a=copy.deepcopy(syokiti)
    for kai,j in enumerate(a):
        if j == "?":
            a[kai]=i[yousuu]
            yousuu+=1
    
    ls = [j+1 for j in range(len(a))]
    handan = []
    for j in itertools.combinations(ls,2):
        
        j = list(j)
        renzoku=0
        saisyo=a[0]
        saikouti=0
        for k in range(j[0]-1,j[1]):
            if a[k] == saisyo:
                renzoku += 1
            else:
                saisyo = a[k]
                renzoku = 1
            if saikouti < renzoku:
                saikouti = renzoku
                
        handan.append(saikouti)
    last.append(max(handan))

print(min(last))