line = list(input()) l_dic = {} for i in line: if i in l_dic: l_dic[i] +=1 else: l_dic[i] =1 a = l_dic["A"] b = l_dic["B"] if a ==0 or b ==0: print(0) elif a > b: print(b) else: print(a)