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