n = int(input()) s = input() cnt, bb = 0, 0 for i in range(n-1): if s[i] + s[i+1] == "BB": bb = 1 else: cnt += 1 for i in range(n-2): if s[i:i+3] == "BAB": cnt -= 1 print(cnt+bb)