s=input() c=0 while 'BA' in s: s=s.replace('BA','AB',1) c+=1 print(c)