n=int(input()) s=list(input()) ans=0 f = 0 for i in range(n): if i - 2 >= 0: if s[i] == 'B' and s[i-2] == 'B' and s[i-1] == 'A': ans -= 1 if i < n-1: if s[i] == 'B' and s[i+1] == 'B': if f==0: ans+=1 f=1 else: ans+=1 print(ans)