import itertools n = int(input()) s = input() A = [(k, len(list(g))) for k, g in itertools.groupby(s)] ans = 0 for i in range(len(A)): if A[i][0] == "A": if A[i][1] == 1: ans += 1 else: ans += A[i][1] + 1 ans += "BB" in s ans -= (A[0][0] == "A" and A[0][1] != 1) + (A[-1][0] == "A" and A[-1][1] != 1) print(ans)