def next(l,m,index):
  for i in range(index+1,len(m)):
    if m[i]:return i
    
def previous(l,m,index):
  if len(l)==0:
    return -1
  for i in range(index-1,-1,-1):
    if m[i]:return i
  return -1
  
s = raw_input()
n = len(s)
m = [True]*n #The boolean array
if len(list(set(list(s))))==1:print 1;exit()
i=0
stack = []
point = 0 #or -1
minpoint = point
maxpoint = point
index = -1 # Will be made into  some value
maxstack = 0
while i<n: # The only loop, not counting the next/previous functions
  #print stack,point,"point"
  #print stack,m,i
  if i!=n-1 and s[i]!=s[i+1]: # The first operation
    #i+=1
    #print stack,m,i,point
    m[i],m[i+1] = False,False
    i+=1
  else: #s[i]==s[i+1]
    #First check if it can be made into a pair with the last element in the stack
    #print stack,m,i,point
    if i==n-1 and stack!=[]:
        if stack[index] !=s[i]:
            point -=1
            stack.pop(index)
            if point<minpoint: #point
                minpoint = point
            if point>maxpoint:
                maxpoint = point
            index-=1

    elif stack!=[] and stack[index] !=s[i]:
      #print "Entered"
      m[index],m[i] = False,False
      point -=1
      if point<minpoint: #point
        minpoint = point
      if point>maxpoint:
                maxpoint = point
      stack.pop(index)       #index
      index-=1
      #index = previous(stack,m,index)
    
    else:
      stack.append(s[i])
      if len(stack)>maxstack:
          maxstack = len(stack)
      point+=1
      if point>maxpoint:
          maxpoint = point

      if index==-1:
        index = 0
        #point = 0
      else:
        index+=1
        #index = next(stack,m,index)
        #point+=1
  i+=1
#print abs(minpoint-maxstack),minpoint,maxpoint,maxstack,len(stack),maxpoint-len(stack)+1
print maxpoint-len(stack)+1
