S=input()
l=len(S)
slist=list(S)
cnt=1
rlist=[]
i=1

while(i<l):
  if(slist[i-1]==slist[i]):
    cnt+=1
  else:
    rlist.append([slist[i-1],cnt])
    cnt=1
  i+=1

rlist.append([slist[l-1],1])

j=1
max=0
length=len(rlist)

while(j<length-1):
  a=rlist[j-1][0]
  b=rlist[j-1][1]
  c=rlist[j][0]
  d=rlist[j][1]
  e=rlist[j+1][0]
  f=rlist[j+1][1]
  if(c=="?" and a==e):
    tmpmax=b+f-d
    if(max<tmpmax):
      max=tmpmax
  j+=1

print(max)