N = int(input()) S = input() ans = 0 for i in range(1, N): a, b = S[i-1], S[i] if a == b == 'B': continue if a == 'A' and b == 'B': if i-2 >= 0 and S[i-2] == 'B': continue ans += 1 if 'BB' in S: ans += 1 print(ans)