N = int(input()) S = input() ans = int("BB" in S) if S[0] != "B" or S[1] != "B": ans += 1 for i in range(2, N): if S[i] == "A": ans += 1 else: if S[i-1] == "B": continue elif S[i-1] == "A" and S[i-2] == "B": continue ans += 1 print(ans)