N = int(input()) S = input() cnt = 0 first = 0 for i in range(N-1): if S[i+1]=="A": cnt+=1 elif S[i]=="A": if i>=1 and S[i-1]=="B": pass else: cnt+=1 elif first==0 and S[i]=="B" and S[i+1]=="B": first=1 cnt+=1 print(cnt)