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