import sys
from sys import stdin

N = int(stdin.readline())

bb = 0
other = 0

S = stdin.readline()[:-1]

for i in range(N-1):

    if S[i]+S[i+1] == "BB":
        bb += 1
    else:
        other += 1

ans = other + min(bb,1)

for i in range(N-2):
    if S[i]+S[i+1]+S[i+2] == "BAB":
        ans -= 1

print (ans)