N = int(input()) S = input() R = 0 if "BB" in S: R += 1 for i in range(1, N): if S[i - 1:i + 1] != "BB": if i == 1 or S[i - 2:i + 1] != "BAB": R += 1 print(R)