S=input()
mode0_cnt=0
mode1_cnt=0
ans=1


if "11" in S:
	for h in range(len(S)):
		if mode0_cnt==0 and mode1_cnt==0:
			if S[h]=="0":
				mode0_cnt+=1
			elif S[h]=="1":
				mode1_cnt+=1
		elif mode1_cnt>0:
			if S[h]=="1":
				mode1_cnt+=1
				ans=max(ans,mode1_cnt)
			else:
				mode1_cnt-=1
		else:
			if S[h]=="0":
				mode0_cnt+=1
				ans=max(ans,mode0_cnt)
			else:
				mode0_cnt-=1
	print(ans)

elif "00" in S:
	for h in range(len(S)):
		if mode0_cnt==0 and mode1_cnt==0:
			if S[h]=="0":
				mode0_cnt+=1
			elif S[h]=="1":
				mode1_cnt+=1
		elif mode1_cnt>0:
			if S[h]=="1":
				mode1_cnt+=1
				ans=max(ans,mode1_cnt)
			else:
				mode1_cnt-=1
		else:
			if S[h]=="0":
				mode0_cnt+=1
				ans=max(ans,mode0_cnt)
			else:
				mode0_cnt-=1
	print(ans)

else:
	temp_bef=""
	temp_af=""
	cnt=0
	flag=1
	#?が偶数か奇数か
	for h in range(len(S)):
		if temp_bef=="":
			if S[h]=="1" or S[h]=="0":
				temp_bef=S[h]
		else:
			if S[h]=="?":
				cnt+=1
			elif S[h]==temp_bef:
				if cnt%2==0:
					flag=2
					break
				temp_bef==""
				cnt=0
			else:
				if cnt%2==1:
					flag=2
					break
				temp_bef==""
				cnt=0
	
	print(1 if flag ==1 else 2)