N = int(input()) S = input() zero = 0 one = set() two = set() for i in range(N-1): if S[i:i+2] == "AA": two.add(i) elif S[i:i+2] == "BA": one.add(i+1) elif S[i:i+2] == "AB": one.add(i) else: zero = 1 print(len(one)+len(two)+zero)