N=int(input()) S=input() ans=0 f=0 for i in range(N-1): if S[i]=="B" and S[i+1]=="B": f=1 else: ans+=1 print(ans+f-S.count("BAB"))