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